|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-06-04 21:18 UTC] gauthierm@php.net
Description:
------------
I'd like to be able to safely shut down gearman workers by sending the SIGTERM
signal. I want to either re-queueing or finish the current job before exiting.
Using the PHP process control extension to set up a signal handler doesn't work
when the gearman work loop is running.
If signal handlers are assigned, they are never called during the work loop and
the process can not be ended except for SIGKILL.
If no signal handlers are assigned, SIGTERM and SIGINT work as expected during the
work loop.
Test script:
---------------
<?php
define(ticks = 1);
function handle($signal) {
// shutdown safely
exit();
}
pcntl_signal(SIGTERM, 'handle');
$worker = new GearmanWorker();
// set up worker stuff here
while ($worker->work());
Expected result:
----------------
When SIGTERM is sent to the process, the signal handler should be called.
Actual result:
--------------
When SIGTERM is sent to the process, nothing happens. The process runs forever
until SIGKILL is sent.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 03:00:02 2025 UTC |
This actually doesn't have anything to do with gearman. The problem is that loops block custom signal handlers. The only solution I know of is to call pcntl_signal_dispatch(); whithin your loop. Try replacing your loop with something like this: --------- while (true) { pcntl_signal_dispatch() $worker->work(); }