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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料