|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-09-26 21:23 UTC] dcpiper at indiana dot edu
Description:
------------
I have noticed that even though a class function can be registered as a callback, it is not possible to set/update a class variable from within the signal handler and get it to be set within the actual 'live' instance of that object.
Is this a bug? It seems cumbersome to have to resort to global variables in order to actually DO something with the signal other than print out strings saying 'I got one!'
Reproduce code:
---------------
class SigTest {
var $myvalue;
function SignalHandler($signo) {
echo "Got signal $signo \n";
$this->myvalue = $signo;
echo "in SignalHandler:\n";
var_dump($this);
}
function SigTest() {
declare (ticks = 1);
$this->myvalue = 'some initial state';
echo "Setting signal handlers ... ";
pcntl_signal(SIGTERM, array(&$this, 'SignalHandler'));
pcntl_signal(SIGINT, array(&$this, 'SignalHandler'));
pcntl_signal(SIGHUP, array(&$this, 'SignalHandler'));
$this->something = 'This data was set after the handler was instantiated';
echo "Done\n";
}
}
$jm = new SigTest;
sleep(2);
echo "Generating signal to self...\n";
posix_kill(posix_getpid(), SIGTERM);
echo "Main execution, looking at \$jm object:\n";
var_dump($jm);
Expected result:
----------------
Expected that 'myvalue' class variable change from within signal handler was visible outside of that function, i.e. a change made, not reverted to the state it was in previously before the signal was handled.
Actual result:
--------------
Setting signal handlers ... Done
Generating signal to self...
Got signal 15
in SignalHandler:
object(sigtest)(2) {
["myvalue"]=>
int(15)
["something"]=>
string(52) "This data was set after the handler was instantiated"
}
Main execution, looking at $jm object:
object(sigtest)(2) {
["myvalue"]=>
string(18) "some initial state"
["something"]=>
string(52) "This data was set after the handler was instantiated"
}
Last 'var_dump' SHOULD be the same as the first one, in my opinion.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 12:00:01 2025 UTC |
Yep, with the PHP5 snapshot it works fine. Do I have to upgrade everything to PHP5? The value is set correctly and maintained. I get this now: /usr/src/apbuild/php5-200509301830/sapi/cli/php signaltest.php Setting signal handlers ... Done Generating signal to self... Got signal 15 in SignalHandler: object(SigTest)#1 (2) { ["myvalue"]=> int(15) ["something"]=> string(52) "This data was set after the handler was instantiated" } Main execution, looking at $jm object: object(SigTest)#1 (2) { ["myvalue"]=> int(15) ["something"]=> string(52) "This data was set after the handler was instantiated" }