PHP API接取多个呼叫 [英] PHP API acess multiple calls

查看:144
本文介绍了PHP API接取多个呼叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在电话上通过PHP卷曲PayPal的API TransactionSearch

I am running calls onto PayPal's TransactionSearch API through PHP cURL.

不幸的是,该API是很慢的响应,有时采取任何地方从30秒至5分钟以上(根据记录数从API返回)为单个客户

Unfortunately, the API is very slow to respond, sometimes taking anywhere from 30 seconds to more than 5 minutes (depending on the number of records returned from the API) for a single customer.

目前,脚本运行了一个cron作业,并通过一到每个客户循环。然而,如果客户的数量扩大,整个过程将需要很长的时间(几个小时)完成。这是不够的。

At the moment, the script is running off a cron job, and looping through each customer one by one. However, if the number of customers scale up, the entire process would take a very long time (few hours) to complete. This is not good enough.

从本质上讲,我需要运行(和过程)多个API调用同时进行。什么是实现这一目标的最佳途径?

Essentially, I need to run (and process) multiple API calls simultaneously. What's the best way to achieve this?

推荐答案

由于瓶颈是远程服务器,我建议使用的 curl_multi_exec 。你会立刻处理HTTP连接的大数目,然后处理在一个线程中他们的结果。

Since the bottleneck is the remote server, I suggest using curl_multi_exec. You'll be processing a big number of HTTP connections at once and then process their results in one thread.

这是不是最快的解决方案,这将是尽快他们在多线程处理可用的反应,但这种方法可以使处理而不显著变化快50+倍。

This is not the fastest solution, which would be to process responses as soon as they're available in multiple threads, but this approach can make processing 50+ times faster without significant changes.

这篇关于PHP API接取多个呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆