douye6812
douye6812
2016-06-29 07:31

如何在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 douwanc63652 5年前

    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.

    点赞 评论 复制链接分享