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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
50 - 4 = ?
Subscribe to this entry?

 
 [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 Apr 19 19:01:28 2024 UTC