|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39972 pcntl_signal not working
Submitted: 2006-12-28 05:27 UTC Modified: 2006-12-28 17:34 UTC
From: kementeus at gmail dot com Assigned:
Status: Not a bug Package: PCNTL related
PHP Version: 5.2.0 OS: Debian 3.1
Private report: No CVE-ID: None
 [2006-12-28 05:27 UTC] kementeus at gmail dot com
pcntl_signal is not executing the code inside the function handling of the signal. The code example is taken from the php manual in and modified just to echo a simple text

Reproduce code:

$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";
         case SIGHUP:
             // handle restart tasks
             // 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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-28 10:00 UTC]
Move pcntl_signal() somewhere BEFORE endless loop, so it gets called after all.
 [2006-12-28 17:24 UTC] kementeus at gmail dot com
Fixed when moving the pcntl_signal before the loop, now submitting the fixing in the documentation
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 07:01:30 2024 UTC