Search code examples
phpresquecomposer-phpphp-resque

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 php-resque library was installed using Composer.

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

View Source

enter image description here


Solution

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

    <?php 
    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
    $worker->pruneDeadWorkers();
    

    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.