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

From: Date: Wed, 31 Oct 2018 16:50:22 +0000
Subject: Bug #77090 [NEW]: socket does not close when exec running in the background
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217775@lists.php.net to get a copy of this message
From:             jas at eecs dot yorku dot ca
Operating system: Linux
PHP version:      7.2.11
Package:          Sockets related
Bug Type:         Bug
Bug description:socket does not close when exec running in the background

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 bug report at https://bugs.php.net/bug.php?id=77090&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=77090&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=77090&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=77090&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=77090&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=77090&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=77090&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=77090&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=77090&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=77090&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=77090&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=77090&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=77090&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=77090&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77090&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=77090&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=77090&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=77090&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77090&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=77090&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=77090&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#217775) next »