Bug #77090 [Dup]: socket does not close when exec running in the background

From: Date: Wed, 31 Oct 2018 17:18:11 +0000
Subject: Bug #77090 [Dup]: socket does not close when exec running in the background
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217778@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77090&edit=1

 ID:                 77090
 User updated by:    jas at eecs dot yorku dot ca
 Reported by:        jas at eecs dot yorku dot ca
 Summary:            socket does not close when exec running in the
                     background
 Status:             Duplicate
 Type:               Bug
 Package:            Streams related
 Operating System:   Linux
 PHP Version:        7.2.11
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2018-10-31 17:03:27] 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 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)

« previous php.bugs (#217778) next »