note 66808 added to function.pcntl-signal

From: Date: Tue, 30 May 2006 03:43:30 +0000
Subject: note 66808 added to function.pcntl-signal
Groups: php.notes 
Request: Send a blank email to php-notes+get-112522@lists.php.net to get a copy of this message
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 ---- Server IP: 216.194.113.175 Probable Submitter: 69.244.181.136 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.pcntl-signal.php Edit -- http://master.php.net/note/edit/66808 Del: integrated -- http://master.php.net/note/delete/66808/integrated Del: useless -- http://master.php.net/note/delete/66808/useless Del: bad code -- http://master.php.net/note/delete/66808/bad+code Del: spam -- http://master.php.net/note/delete/66808/spam Del: non-english -- http://master.php.net/note/delete/66808/non-english Del: in docs -- http://master.php.net/note/delete/66808/in+docs Del: other reasons-- http://master.php.net/note/delete/66808 Reject -- http://master.php.net/note/reject/66808 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#112522) next »