doushan3511 2014-01-09 14:55
浏览 31
已采纳

使用CakePHP的HttpSocket或PHP的cURL从搜索页面抓取多个站点

I am going to use CakePHP to build an application that allows users to search for a keyword, ie. milk, and then I would automatically search local online stores for best pricing on milk, ie. walmart, shaws, stop&shop, etc. (Note: this is a hypothetical situation, exemplifying what I need accomplished), and then I would display the results to the user.

I want to take advantage of CakePHP's HttpSocket library to accomplish this instead of cURL.

I will need to have this setup as multi-thread so I can display the results quicker, but for performance's sake, where is the best place to make these call, ie Controller? Basically, I am looking for your insight into the best approach to have something like that work, considering it needs to be multi-thread, and fast.

I have not used CakePHP's HttpSocket library before, but I have looked thru it and tested it quickly and it seems to be very powerful. What is your take on that? Does it compare performance-wise to PHP's cURL?

Your insight is much appreciated.

  • 写回答

1条回答 默认 最新

  • doupafu6980 2014-01-09 16:28
    关注

    cURL is faster than any plain php implementation like the CakePHP socket is.

    Controller is the wrong place, model or a custom datasource would be the proper place. You can request multiple sites at the same time and wait X seconds until you cancel the requests that have not responded in time. Also I would cache the results so that you don't have to request the price each time.

    Depending on how often the prices change it might be a much better idea to just query all your shops one or two times per day or hourly for example using a shell and update the prices in your database.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用