steverobbins/magescan

Make requests asyncronous

Closed this issue · 4 comments

Right now it's sending requests synchronously, which takes longer. We should make use of the curl_multi_* functions.

Guzzle has support for async requests if you'd rather use their library instead of building it yourself. (There might be other lighter libraries too, I'm just not familiar with any.)

I've been checking out Guzzle recently to see if we could try and eliminate the use of curl in our own codebases where it makes sense, but hadn't found a small enough sample to dig in yet.

It looks like it would be a pretty solid alternative and also a simpler solution to stay native php as the syntax for streams looks pretty easy to grok first glance.

// Send an asynchronous request.
$request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');
$promise = $client->sendAsync($request)->then(function ($response) {
    echo 'I completed! ' . $response;
});
$promise->wait();

There do seem to be some minor requirements to address depending on which route you want to go. None are deal breakers for me, but before i start digging into this do any of these limitations matter or do were you thinking you might prefer curl as the first attempt?


Requirements

 * PHP 5.5.0
 * To use the PHP stream handler, allow_url_fopen must be enabled in your system's php.ini.
 * To use the cURL handler, you must have a recent version of cURL >= 7.19.4 compiled with OpenSSL and zlib.
 * Note : Guzzle no longer requires cURL in order to send HTTP requests. Guzzle will use the PHP stream wrapper to send HTTP requests if cURL is not installed. Alternatively, you can provide your own HTTP handler used to send requests.

Given that PHP 5.4 only has a couple month until EOL I'm okay with dropping it's support. All the other requirements are reasonable.

This has been added in version 1.12.0