|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77090 socket does not close when exec running in the background
Submitted: 2018-10-31 16:50 UTC Modified: 2018-10-31 17:18 UTC
From: jas at eecs dot yorku dot ca Assigned:
Status: Duplicate Package: Streams related
PHP Version: 7.2.11 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jas at eecs dot yorku dot ca
New email:
PHP Version: OS:


 [2018-10-31 16:50 UTC] jas at eecs dot yorku dot ca
The example below is similar to the one posted on the documentation from stream_socket_server on PHP site:

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:
$socket = stream_socket_server("tcp://", $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 &");

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-31 17:03 UTC]
-Status: Open +Status: Duplicate -Package: Sockets related +Package: Streams related
 [2018-10-31 17:03 UTC]
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
The same root cause as
 [2018-10-31 17:18 UTC] jas at eecs dot yorku dot ca
It wasn't clear to me that this was the same problem as in the other report.
Sorry for the duplicate, but I spent a whole day working on this, and took the time to break it down into a smaller sample.
However, there is no resolution to the other report in 4 years!?  I guess this isn't something that will be solved then.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 22 17:01:44 2024 UTC