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

使用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
    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.

    点赞 评论

相关推荐