ID:               39972
 User updated by:  kementeus at gmail dot com
 Reported By:      kementeus at gmail dot com
-Status:           Bogus
+Status:           Closed
 Bug Type:         PCNTL related
 Operating System: Debian 3.1
 PHP Version:      5.2.0
 New Comment:

Fixed when moving the pcntl_signal before the loop, now submitting the
fixing in the documentation


Previous Comments:
------------------------------------------------------------------------

[2006-12-28 10:00:54] [EMAIL PROTECTED]

Move pcntl_signal() somewhere BEFORE endless loop, so it gets called
after all.

------------------------------------------------------------------------

[2006-12-28 05:27:12] kementeus at gmail dot com

Description:
------------
pcntl_signal is not executing the code inside the function handling of
the signal. The code example is taken from the php manual in
http://www.php.net/manual/en/ref.pcntl.php and modified just to echo a
simple text

Reproduce code:
---------------
<?php
declare(ticks=1);

$pid = pcntl_fork();
if ($pid == -1) {
     die("could not fork"); 
} else if ($pid) {
     exit(); // we are the parent 
} else {
     // we are the child
}

if (!posix_setsid()) {
   die("could not detach from terminal");
}

while (1) {
   // do something interesting here
}

function sig_handler($signo) 
{
     switch ($signo) {
         case SIGTERM:
             // handle shutdown tasks
             echo "I need to execute\n";
             exit;
             break;
         case SIGHUP:
             // handle restart tasks
             break;
         default:
             // handle all other signals
     }

}

// setup signal handlers
pcntl_signal(SIGTERM, "sig_handler");
pcntl_signal(SIGHUP, "sig_handler");
?> 

Expected result:
----------------
When you send the signal SIGTERM with kill -15 PID the process should
echo the message "I need to execute" and then terminate.

Actual result:
--------------
The process terminate but doesn't echo or execute anything inside the
function handler.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=39972&edit=1

Reply via email to