Async requests in guzzlephp (or php-ga-measurement-protocol)

324 Views Asked by At

Does anyone know how to send a working and non-blocking async request using guzzlephp?

There seems to be a support for this but it does not seem to be implemented

<?php

$this->guzzle->requestAsync('post', 'http://', ['synchronous' => false])->wait();

?>

Implemented in a sense that it does not wait for the response.

There is also a problem with php-ga-measurement-protocol

$analytics->setAsyncRequest(true)->sendPageview(); 
1

There are 1 best solutions below

0
Alexey Shokov On

What problem you are talking about?

Async requests work fine in Guzzle, exactly as you described. You just get a promise from requestAsync() immediately, do other stuff and take the response, when you are ready.

// ['synchronous' => false] is not required.
$responsePromise = $this->guzzle->requestAsync('post', 'http://...');

// Your stuff...

$response = $responsePromise->wait();

Don't know about php-ga-measurement-protocol, BTW, but seems that this lib implements them correctly too.