Respond to request before processing is done. Threads? Async? Workers? Queues? Multiprocessing?

Hi!

I have a performance issue in a cakephp application I’m maintaining.

When the user makes a requests to one of our endpoints, my Controller starts to make API calls to a third party service to send e-mails. But making these API requests takes some time and I want to send back a response to my users before the calls to the third party service has completed. (The results of the API calls will have no impact on the response to my user)

I want to be able to send the response to my user quickly because otherwise the user will notice a delay in the web application.

How would you solve an issue like this? Is there support for threads, worker queues, async or multiprocessing or any other concepts the young people are talking about in CakePHP?

Thanks!

/Daniel

What you desire is either

or

which both basically allow you to fill a queue with tasks and a (from the request) separately working runner will perform those tasks in the background.

1 Like

Thank you for your reply! I’ll look into those possible solutions!

What are your thoughts on Introduction — CakePHP Queuesadilla mentioned in CakePHP — Run background jobs using queued events | by Narendra Vaghela | SprintCube Blog | Medium ?

Sure, if you want to use this then go for it.

I am used to dereuromarks queue plugin so I can only tell you good things about that one.

After some comparison between the three options, we are going to choose dereuromark’s plugin since it uses the same database as the rest of the application. Using something like Redis together with cakephp/queue would might perform better but we don’t need that extra infrastructure overhead at this stage.

Also having no dependencies is also good in my view and I really liked the documentation.

I also stumbled upon GitHub - FriendsOfCake/awesome-cakephp: A curated list of amazingly awesome CakePHP plugins, resources and shiny things. while doing a bit more research.

Thank you again for your input!