Guzzle 如何发送异步 Web 请求?

How does Guzzle send async web requests?

cURL 是同步的。那么像 Guzzle 这样的库是如何发送异步网络请求的呢?

Guzzle CurlMultiHander wraps PHP's builtin curl_multi_* function which essentially wrap the cURL Multi API

来自 cURL 文档:

To use the multi interface, you must first create a 'multi handle' with curl_multi_init. This handle is then used as input to all further curl_multi_* functions.

With a multi handle and the multi interface you can do several simultaneous transfers in parallel. Each single transfer is built up around an easy handle. You create all the easy handles you need, and setup the appropriate options for each easy handle using curl_easy_setopt.

允许异步传输的 Guzzle's transport handlers is CurlMultiHandler that uses PHP's curl_multi_* 函数之一。

请求是异步启动的,函数 curl_multi_select() 允许 Guzzle 等到其中一个 curl 请求接收到数据并进行处理。