Bug #77090 [Opn->Dup]: socket does not close when exec running in the background
Edit report at https://bugs.php.net/bug.php?id=77090&edit=1
ID: 77090
Updated by: daverandom@php.net
Reported by: jas at eecs dot yorku dot ca
Summary: socket does not close when exec running in the
background
-Status: Open
+Status: Duplicate
Type: Bug
-Package: Sockets related
+Package: Streams related
Operating System: Linux
PHP Version: 7.2.11
Block user comment: N
Private report: N
New Comment:
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same.
Thank you for your interest in PHP.
Duplicate of https://bugs.php.net/bug.php?id=67383
The same root cause as https://bugs.php.net/bug.php?id=43290
Previous Comments:
------------------------------------------------------------------------
[2018-10-31 16:50:22] jas at eecs dot yorku dot ca
Description:
------------
The example below is similar to the one posted on the documentation from stream_socket_server on PHP
site:
http://php.net/manual/en/function.stream-socket-server.php
I added the "exec" line after the fwrite.
Before adding the exec line, after the client connects to port 8000, the local time and date is
printed, and the client connection is closed. After adding the exec line, the fclose runs and even
returns success, but the client connection doesn't close. The PHP code does continue to
execute, so the process is running in the background. It's not clear to me why the client
isn't disconnected after running the fclose.
Test script:
---------------
#!/bin/php72
<?php
$socket = stream_socket_server("tcp://0.0.0.0:8000", $errno, $errstr);
if (!$socket) {
echo "$errstr ($errno)<br />\n";
} else {
while ($conn = stream_socket_accept($socket)) {
fwrite($conn, 'The local time is ' . date('n/j/Y g:i a') .
"\n");
exec("nohup sleep 200 >/dev/null &");
fclose($conn);
}
fclose($socket);
}
?>
Expected result:
----------------
I want the local date and time printed, then the connection to close immediately.
Actual result:
--------------
The date and time is printed, but then the connection hangs.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77090&edit=1
Thread (3 messages)