ID: 34650
User updated by: dcpiper at indiana dot edu
Reported By: dcpiper at indiana dot edu
-Status: Feedback
+Status: Open
Bug Type: PCNTL related
Operating System: Linux 2.6.13.1 (Debian Sarge)
PHP Version: 4.4.0
New Comment:
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"
}
Previous Comments:
------------------------------------------------------------------------
[2005-09-27 19:09:19] [EMAIL PROTECTED]
Please try using this CVS snapshot:
http://snaps.php.net/php5-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5-win32-latest.zip
------------------------------------------------------------------------
[2005-09-26 21:23:09] 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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=34650&edit=1