|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-07-31 19:40 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 24 12:00:01 2025 UTC |
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?