⚠️ Warning ⚠️
This article was written 3 years and 7 months ago. The informations it contains may be outdated or no longer relevant.
If you have to make some external API call during a process, but you have no need to wait the response to return result to the user, this tip can help you:
On Symfony, the kernel.terminate
event is launched after the response has been sent to the user.
The response from symfony/http-client is by design asynchronous, but when the object is destroyed, it'll wait the request is completed (see here).
By keep the response instance and using it in kernel.terminate
event, we don't have to wait the request is completed before render result to user.
If you use Laravel >= 8.x, you can also dispatch event after response is sent :