Non-blocking calls in PHP with GuzzleHttp REST API client
09:51 09 Apr 2015

I would like to make a non-blocking REST API call using PHP library GuzzleHttp.

  1. I have a REST API server (http://api.example.com/v1/wait)
  2. wait method does not do anything, except sleep(10).
  3. I am running the following from PHP CLI with future param:
$client = new \GuzzleHttp\Client;
$response = $client->get('http://api.example.com/v1/wait', [
    'future' => true,
    'body' => [
        'some' => 'var'
    ],
]);
echo 'OK';

I am expecting that "OK" would echo immediately, without waiting for completion of REST API call. Instead, the execution is suspended for 10 seconds - that is the sleep() duration in REST wait() method.

According to Guzzle documentation:

You can send asynchronous requests by setting the future request option to true

I am not interesting in call completion callbacks, all I want is to give API some (possibly, slow) task to work on and get on with life.

I have also tried cURL's own multirequest, several other libraries - the result is the same. Execution is blocked, waiting for response to arrive from API server.

So, what could be the problem?

Thanks!

php rest guzzle