php.net |  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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-31 17:03 UTC] daverandom@php.net
-Status: Open +Status: Duplicate -Package: Sockets related +Package: Streams related
 [2018-10-31 17:03 UTC] daverandom@php.net
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
 [2018-10-31 17:18 UTC] jas at eecs dot yorku dot ca
Hi.
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: Mon Dec 30 14:01:28 2024 UTC