douye6812 2016-06-29 07:31
浏览 630

如何在PHP中优化多个CURL get请求的速度?

I'm connecting to an API with PHP through a CURL GET and I receive a json with almost 5000 orders. For every order I make another CURL GET and receive the order details (basically 2 foreach). After that I make some inserts and updates in the database (basic stuff) with LARAVEL.

The big problem is that for those 5000 orders I have a loading time of almost one hour. I need to this with a cron every night (and for more than 5000).

I have a cloud solution with 2GB Memory and 2 CoreProcessor.

I tried also Zebra Curl but cannot use that with curl in curl request.

  • 写回答

1条回答 默认 最新

  • douwanc63652 2016-06-29 08:02

    if 2% of the daily jobs (1 of 50 organisations) takes almost 4% of a day you definitely need parallel processing.

    There are several solutions for that:

    • Run a cron job for each organisation.
    • Process entries for multiple companies in 1 multi-curl call.
    • Use multiple servers.

    I would probably use the first one: You could have a cron job check (every minute?) which organisations still need to be processed and which organisations are being processed at the moment and pick one if there are any left.

    That way each job would still take 1 hour but all would be processed in the time-span of 2 hours each night.

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



  • ¥15 光纤中多普勒频移公式的推导
  • ¥15 怎么制作一个人脸识别门禁系统
  • ¥20 大华dss监控平台网络关闭登不进去
  • ¥15 请使用蚁群算法解决下列问题,并给出我完整的代码
  • ¥20 关于php录入完成后,批量更新数据库
  • ¥15 请教往复密封润滑问题
  • ¥15 cocos creator发布ios包
  • ¥15 comsol压电材料数据
  • ¥35 用python实现除法算法中goldschmidt算法
  • ¥15 汇编代码转换成C代码