Bug #71448 [NEW]: declare(ticks=1) limited to scope of file makes Signal handling difficult

From: Date: Mon, 25 Jan 2016 21:42:20 +0000
Subject: Bug #71448 [NEW]: declare(ticks=1) limited to scope of file makes Signal handling difficult
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198889@lists.php.net to get a copy of this message
From:             dave at atst dot io
Operating system: Linux
PHP version:      7.0Git-2016-01-25 (Git)
Package:          PCNTL related
Bug Type:         Bug
Bug description:declare(ticks=1) limited to scope of file makes Signal handling difficult

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 bug report at https://bugs.php.net/bug.php?id=71448&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=71448&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=71448&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=71448&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=71448&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=71448&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=71448&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=71448&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=71448&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=71448&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=71448&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=71448&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=71448&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=71448&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71448&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=71448&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=71448&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=71448&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71448&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=71448&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=71448&r=mysqlcfg



Thread (5 messages)

« previous php.bugs (#198889) next »