Running Asynchronous Code in Slim 4

I’m using Slim Framework as my backend. In one of the endpoint, myurl.com/xyz, I’m writing to my database and then redirecting user to another website. As far as I know, each code runs sequential. So, the user will be redirected after the database insert operation.

I want to make that database insert operation asynchronous like going into a queue and redirecting the user instantaneously.
The queue manager will handle the database operation asynchronously.

What could be the best way to implement it. I’ve seen Guzzle with Promise but unsure how to implement a function with it. I’ve read about calling an API endpoint with it.
Is there any good queue management for task that works good with Slim framework according to my requirements?

Hello!

I think if you need to perform async commands maybe you can use a Queue Service like RabbitMQ or AWS SQS.

So, when you receive a request, send an async message to a queue, and then make the redirect.

Then, a worker/consumer is listening in the queue, and when receive a new message they process the message and make the insert in your database.

Examples:

https://www.rabbitmq.com/tutorials/tutorial-one-php.html

https://www.rabbitmq.com/getstarted.html

You can install and integrate the php-amqplib client library in a Slim project using composer.

Thank you. I’m testing it.