Hello. In my api I use guzzle for assync requests and Sentry for the logs.
The sentry library needs the php7.0-curl installation.
In the terminal I type:
sudo apt-get install php7.0-curl
After that my requests using the postAsync function does not work anymore.
Only work if I call the wait function on the promisse returned from postAsync.
Is this behavior correct?
Thanks
does not work
sudo apt-get install php7.0-curl
$this->client = new \GuzzleHttp\Client();
return $this->client->postAsync(env("PUSH_URL"), $this->headers);
Its work
sudo apt-get install php7.0-curl
$this->client = new \GuzzleHttp\Client();
return $this->client->postAsync(env("PUSH_URL"), $this->headers)->wait(false);`
Yes, the described behaviour is correct. You have to call ->wait() (or use other functions like all(), any(), settle()...) if you want to be sure that your request is completed. That doesn't mean, BTW, that you have to call ->wait() right after the call (why would you use Async calls then).
If you use Guzzle to send info to Sentry (means that you don't need the response), you can finish the main HTTP request to you script and wait for Santry after it:
$request = $this->client->postAsync(env("PUSH_URL"), $this->headers);
// ... your actions ...
// Finish the request (you won't be able to send any data after that). Only if you are using PHP-FPM.
fastcgi_finish_request();
// Wait for Santry.
$request->wait();
I do not think I explained it right.
I use Guzzle to make requests to my push notification server. It's a real-time application, so I can not wait for the response from that service.
To integrate my api with sentry I use their sdk (not with guzzle), however its sdk needs the installation of the php7.0-curl package.
https://launchpad.net/ubuntu/xenial/+package/php7.0-curl
As soon as I install the php7.0-curl package
sudo apt-get install php7.0-curl
the asynchronous requests for my push notification server (which use guzzle) stop working (the request does not arrive at the destination) unless I call the wait function as described above.
If I uninstalled the php7.0-curl package,
sudo apt-get remove php7.0-curl
the asynchronous requests will be restored immediately without using the wait function.
OK, now your situation is more clear.
My previous message still makes sense, but it's not the main thing.
If you use Guzzle _without_ cURL installed, it sticks to StreamHandler to make HTTP requests. And this handler doesn't support parallel requests at all. So, you code works without php7.0-curl just because all requests are blocking (no parallel requests). I mean that call to ->postAsync() blocks inside and returns only after the request is done, no differences from just ->post().
When you install cURL extension, Guzzle starts to use cURL as the handler, and your async queries become parallel. And you code doesn't work anymore because you don't handle async properly (now it's time for my previous comment).
So you code works only because there is no parallel actions with cURL. Change it as I described in my previous comment, and it should be fine.
Ok.. Thanks. Sorry for the delay.
Most helpful comment
OK, now your situation is more clear.
My previous message still makes sense, but it's not the main thing.
If you use Guzzle _without_ cURL installed, it sticks to
StreamHandlerto make HTTP requests. And this handler doesn't support parallel requests at all. So, you code works withoutphp7.0-curljust because all requests are blocking (no parallel requests). I mean that call to->postAsync()blocks inside and returns only after the request is done, no differences from just->post().When you install cURL extension, Guzzle starts to use cURL as the handler, and your async queries become parallel. And you code doesn't work anymore because you don't handle async properly (now it's time for my previous comment).
So you code works only because there is no parallel actions with cURL. Change it as I described in my previous comment, and it should be fine.