douye6812
2016-06-29 07:31
浏览 383
已采纳

如何在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.

图片转代码服务由CSDN问答提供 功能建议

我通过CURL GET连接到PHP的API,我收到了一个包含近5000个订单的json。 对于每个订单,我进行另一个CURL GET并接收订单详细信息(基本上是2个foreach)。 之后我用LARAVEL在数据库中进行了一些插入和更新(基本的东西)。

最大的问题是,对于那5000个订单,我的加载时间差不多一个小时。 我需要每晚使用一个cron(超过5000)。

我有一个2GB内存和2个CoreProcessor的云解决方案。

我也尝试过Zebra Curl,但在curl请求中不能使用curl。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    点赞 打赏 评论

相关推荐 更多相似问题