How does Guzzle send asynchronous web requests?

cURL is synchronous. So how do libraries like Guzzle send asynchronous web requests?

+5
source share
2 answers

One of the Guzzle transport handlers is CurlMultiHandler , which uses the PHP functions curl_multi_* , which allows asynchronous transfers.

Queries are run asynchronously, and the curl_multi_select() function allows Guzzle wait for one of the swirl requests to receive data and process it.

+4
source

Guzzle CurlMultiHander wraps the built-in PHP curl_multi_ * which essentially completes the cURL Multi API

From the cURL docs:

To use the multi interface, you must first create a "multi handle" with curl_multi_init. This descriptor is then used as input for all additional curl_multi_ * functions.

With the multi-arm and multi-interface, you can perform multiple simultaneous transmissions in parallel. Each individual gear is created around a simple handle. You create all the convenient descriptors you need and configure the appropriate parameters for each simple descriptor using curl_easy_setopt.

+3
source

Source: https://habr.com/ru/post/1243953/


All Articles