I've two urls, a fast and a slow one, the slow url outputs after a delay of 2 sec while the fast one outputs instantly.
I'm using them to get my head around how guzzle works.
In my code, I create two promises, client->get(fast url) and client->get(slow url) and they both have handlers which will echo the response code. From what I understand, the fast url promise should echo the response code first but in my code it always works in the sequential order only. Which ever handler I declare first gets executed first.
My code is
$client = new Client();
$promise_slow = $client->get('http://127.0.0.1:3000/slow', ['future' => true]);
$promise_slow->then(function ($response) {
echo 'Got a response for slow! ' . $response->getStatusCode();
});
$promise_fast = $client->get('http://127.0.0.1:3000/fast', ['future' => true]);
$promise_fast->then(function ($response) {
echo 'Got a response for fast! ' . $response->getStatusCode();
});
I'm using it from inside laravel if that matters.
Is there something I am doing wrong here?
The behavior I want is, if the fasturl outputs first, its response code should get printed before the slower one, which ever order I give them in.