Bug #71448 [Com]: declare(ticks=1) limited to scope of file makes Signal handling difficult
| From: | nathan dot renniewaldock at gmail dot com | Date: | Mon, 25 Apr 2016 01:19:42 +0000 |
| Subject: | Bug #71448 [Com]: declare(ticks=1) limited to scope of file makes Signal handling difficult | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200754@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71448&edit=1
ID: 71448
Comment by: nathan dot renniewaldock at gmail dot com
Reported by: dave at atst dot io
Summary: declare(ticks=1) limited to scope of file makes
Signal handling difficult
Status: Open
Type: Bug
Package: PCNTL related
Operating System: Linux
PHP Version: 7.0Git-2016-01-25 (Git)
Block user comment: N
Private report: N
New Comment:
I've noticed this too.
I've got an IRC bot in PHP, I'm handling SIGINT to clean up before exiting.
With declare(ticks=1] in an included file,
in 5.6.20: triggered near instant
in 7.0.4: can take up to 20 seconds. Near instant after moving declare to the main file.
There's also no mention of this change in the migration guide.
Previous Comments:
------------------------------------------------------------------------
[2016-01-25 21:42:16] dave at atst dot io
Description:
------------
Not sure if this is intended behaviour or fallout from other declare directives intending to be
scoped to a particular file.
The manual states:
The declare construct can also be used in the global scope, affecting all code following it (however
if the file with declare was included then it does not affect the parent file).
I've attached a script that tries to show what I'm trying to do automatically, but you can
remove the forking and just try and ctrl-c from your terminal.
Test script:
---------------
<?php
declare(ticks=1);
$start = time();
pcntl_signal(SIGINT, function() use ($start) {
$diff = time() - $start;
echo "SIGINT received after $diff seconds\n";
exit;
});
$id = posix_getpid();
$child = pcntl_fork();
if ($child) {
include 'inc.php';
} else {
posix_kill($id, SIGINT);
}
## inc.php
<?php
$a = 0;
$start = time();
while(time() < $start + 5) {
$a = $a + 2; # something tickable
}
Expected result:
----------------
SIGINT received after 0 seconds
Actual result:
--------------
SIGINT received after 5 seconds
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71448&edit=1