ID: 38273
User updated by: axelluttgens at swing dot be
Reported By: axelluttgens at swing dot be
Status: Open
Bug Type: PCNTL related
Operating System: Mac OS 10.4.7
PHP Version: 4.4.2
New Comment:
As a follow-up: a "switch" statement, instead of reproduce code's "if"
statement, does not seem to be affected by the problem.
So, replacing the while loop in reproduce code with this one:
while (!socket_select($r = array($endpoint), $w = NULL, $e = NULL,
NULL))
switch ($err = socket_last_error())
{
case SOCKET_EINTR:
socket_clear_error();
PollSigs();
break;
default:
echo "socket_select() failed with $err\n";
break 2;
}
I get the expected behavior back (without having to resort to the
"dummy statement" kludge):
$ /Volumes/Data/Sources/sigtest.php
^C
Warning: socket_select() unable to select [4]: Interrupted system call
in /Volumes/Data/Sources/sigtest.php on line 32
Received SIGINT
Handling SIGINT
^C
Warning: socket_select() unable to select [4]: Interrupted system call
in /Volumes/Data/Sources/sigtest.php on line 32
Received SIGINT
Handling SIGINT
Could this be of some help for narrowing the cause?
Previous Comments:
------------------------------------------------------------------------
[2006-08-01 11:59:14] axelluttgens at swing dot be
Hello Tony, thanks again for your follow up!
For various reasons, I am currently really stuck with PHP 4 here. In
that sense, PHP 5 isn't an alternative for me yet.
But perhaps were you considering a very precise point?
Do you want me to try something else?
TIA,
Axel
------------------------------------------------------------------------
[2006-07-31 20:13:53] [EMAIL PROTECTED]
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5.2-win32-latest.zip
------------------------------------------------------------------------
[2006-07-31 19:40:17] axelluttgens at swing dot be
Description:
------------
It seems there is a problem with the construction of the return address
to be used after an interrupt handler.
Now, I'm not sure whether the problem is a general one, or more
precisely located in the socket_xxx() family of functions.
I used the socket_select() function for building the example, as I
needed a function whose execution is liable to be suspended until the
occurence of an interrupt.
But the "workaround" described hereafter anyway seems to reveal some
misbehavior.
Reproduce code:
---------------
Create an executable file, say "sigtest.php", with following contents:
#!/usr/local/bin/php
<?php
declare(ticks = 1);
$gotINT = FALSE;
function SaveINT()
{
$GLOBALS['gotINT'] = TRUE;
echo "Received SIGINT\n";
}
function HandleINT()
{
echo "Handling SIGINT\n";
}
function PollSigs()
{
if ($GLOBALS['gotINT'])
HandleINT();
}
pcntl_signal(SIGINT, 'SaveINT');
$endpoint = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($endpoint, '127.0.0.1', 12345);
socket_listen($endpoint, 10);
while (!socket_select($r = array($endpoint), $w = NULL, $e = NULL,
NULL))
if (($err = socket_last_error()) === SOCKET_EINTR)
{
# $err = $err;
PollSigs();
}
else
{
echo "socket_select() failed with $err\n";
exit(1);
}
?>
Expected result:
----------------
During execution of above file on the terminal, a break (^C) should
result in:
1. the capture of SIGINT, and thus the execution of SaveINT(),
2. the continuation of execution after socket_select(), and thus the
execution of HandleINT() consecutively to the call of PollSigs().
Actual result:
--------------
[1] With above code, launching the executable yields:
$ /Volumes/Data/Sources/sigtest.php
^C
Warning: socket_select() unable to select [4]: Interrupted system call
in /Volumes/Data/Sources/sigtest.php on line 31
Received SIGINT
^C
Warning: socket_select() unable to select [4]: Interrupted system call
in /Volumes/Data/Sources/sigtest.php on line 31
Handling SIGINT
Received SIGINT
[2] Now, uncomment the
# $err = $err;
line in the source and launch the executable again:
$ /Volumes/Data/Sources/sigtest.php
^C
Warning: socket_select() unable to select [4]: Interrupted system call
in /Volumes/Data/Sources/sigtest.php on line 31
Received SIGINT
Handling SIGINT
^C
Warning: socket_select() unable to select [4]: Interrupted system call
in /Volumes/Data/Sources/sigtest.php on line 31
Received SIGINT
Handling SIGINT
The dummy instruction (ie, $err = $err;) thus allows to restore
exepected behavior.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=38273&edit=1