Voting

: nine plus zero?
(Example: nine)

The Note You're Voting On

aeolianmeson at NOSPAM dot blitzeclipse dot com
19 years ago
In at least version 5.1.4, the parameter passed to the handler is not a strict integer.

I have had such problems as trying to add the signal to an array, but the array is completely screwed up when viewed (but not viewed immediately after being added). This occurs when the handler is a method (array($this, 'methodname')), or a traditional functions.

To avoid this bug, typecast the parameter to an integer:
(note that each newline may appear to just be 'n'.)

<?php
print("pid= " . posix_getpid() . "\n");
declare(
ticks=1);
$arrsignals = array();

function
handler($nsig)
{
global
$arrsignals;
$arrsignals[] = (int)$nsig;
print(
"Signal caught and registered.\n");
var_dump($arrsignals);
}

pcntl_signal(SIGTERM, 'handler');

// Wait for signals from the command-line (just a simple 'kill (pid)').
$n = 15;
while(
$n)
{
sleep(1);
$n--;
}

print(
"terminated.\n\n");
var_dump($arrsignals);
?>

Dustin

<< Back to user notes page

To Top