Is it possible to send a request using Symfony HTTP Client without awaiting the response?
In my use-case some requests to my app should notify a third-party service. The response of that service is irrelevant, and the notification is also not crucial. It doesn't matter if it fails due to a timeout or something similar. But these requests shouldn't delay my app's response. I want "fire and forget".
I use the following controller action to experiment:
class MyController extends AbstractController
{
#[Route('/', name: 'test', methods: ['GET'])]
public function fireAndForget(HttpClientInterface $http): Response
{
$res = $http->request(
'POST',
'https://httpstat.us/201?sleep=5000',
['json' => ['x' => 'y']]
);
return new Response('done');
}
}
Using the debugger, I can step immediately to the return after the request. But the response isn't returned before the request has completed.
I'm using Symfony 6.0 and have curl extensions installed, so Symfony HTTP Client uses CurlHttpClient under the hood.