1

I have a PHP web application with a particularly slow endpoint and I have diagnosed that this is being caused by a complicated function call.

It is not essential that the function call is completed before the response is returned which means that the function call could be put on a queue and executed by a worker. It does need to be executed within ten seconds though.

The problem I have is that I cannot change the infrastructure this web application runs on in any way. This is far from ideal but it is an immovable business requirement. I only have Cron, MySQL, Redis, Apache and PHP at my disposal.

How can I implement a worker system using only Cron?

I'm fairly certain that using Redis to store the queue of function calls is a good start. Could I use Cron as a poor man's replacement to Supervisor to kick start the worker script? Possibly in conjunction with flock to avoid Cronjobs overlapping?

Another idea I had was to use Cron to run the worker script every second. However Cron doesn't support units smaller than minutes so I would have to write a Bash script which does some sort of looping to achieve this.

If anyone has any more robust or sensible or proven ideas I would love to hear them. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.