Nyxynyx Nyxynyx - 1 year ago 117
PHP Question

How to manually prune and restart php-resque workers

Very frequently php-Resque workers will be stuck on a job for days, and eventually all the workers gets stuck and the site stops working.The

library was installed using Composer.

Question: I want to do the pruning manually. How do I access this function
? And if dead workers are found, how do I restart them?

View Source

enter image description here

Answer Source

To prune the workers manually, include the vendor/chrisboulton/php-resque/lib/Resque/Worker.php file, instantiate a Worker, then call pruneDeadWorkers();

include 'vendor/chrisboulton/php-resque/lib/Resque/Worker.php'; // If you're not already using composer autoloader

$worker = new Worker('default'); // the argument doesn't matter

php-resque is not shipped with a function to restart workers, take a look at fresque for that.

To avoid having dead workers, compile your php with pcntl_fork, to execute your jobs in a fork, and isolating them from the workers.