php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62413 sleep() strange behavior on pcntl signal event
Submitted: 2012-06-25 19:38 UTC Modified: 2012-06-25 23:06 UTC
From: merlyn dot tgz at gmail dot com Assigned:
Status: Closed Package: PCNTL related
PHP Version: 5.3.14 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: merlyn dot tgz at gmail dot com
New email:
PHP Version: OS:

 

 [2012-06-25 19:38 UTC] merlyn dot tgz at gmail dot com
Description:
------------
If we install any signal handler and send that signal to our script proccess 
while sleep() function is running script will immideatly continue running from 
next string after sleep() execution. For reproduce you need to open two 
consoles, in first of them execute the script

$ php test.php

in second - determine it's pid

$ ps ax|grep php test.php

and send signal to script proccess

$ kill -s SIGHUP 12990

In provided output example i had wait while first iteration of while loop run 
completely, and after that have sent four times SIGHUP signal from other 
terminal

Test script:
---------------
<?php
declare(ticks=1);
function echo_sig($sigNum)
{
        echo "caught sig: $sigNum\n";
}

pcntl_signal(SIGHUP, 'echo_sig');
$a = 0;

while ($a < 5) {
        $a++;
        $startTime = time();
        sleep(10);
        echo "slept " . (time() - $startTime) . " seconds\n";
}

Expected result:
----------------
slept 10 seconds
caught sig: 1
slept 10 seconds
caught sig: 1
slept 10 seconds
caught sig: 1
slept 10 seconds
caught sig: 1
slept 10 seconds


Actual result:
--------------
slept 10 seconds
caught sig: 1
slept 4 seconds
caught sig: 1
slept 2 seconds
caught sig: 1
slept 0 seconds
caught sig: 1
slept 8 seconds


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-25 23:06 UTC] merlyn dot tgz at gmail dot com
not a bug. I had reread about sleep() ) It's normal behavior, and useful, yeah
 [2012-06-25 23:06 UTC] merlyn dot tgz at gmail dot com
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 01:01:30 2024 UTC