Bug #62001 [Com]: socket don't close
Edit report at https://bugs.php.net/bug.php?id=62001&edit=1
ID: 62001
Comment by: dark9 at rune dot ws
Reported by: dark9 at rune dot ws
Summary: socket don't close
Status: Not a bug
Type: Bug
Package: Streams related
Operating System: ubuntu
PHP Version: 5.4.3
Block user comment: N
Private report: N
New Comment:
thank for reply.
@laruence
if use 'exec' close fd then shell stream read/write etc have difficulty.
@rasmus
easier to control fd or new shell is good idea.
Previous Comments:
------------------------------------------------------------------------
[2012-05-12 17:08:40] rasmus@php.net
Maybe we need a stream_setfd() call or add it to the stream context options to
give people low-level access to set FD_CLOEXEC on arbitrary stream descriptors.
That would make it a bit easier to control something like this, although it is a
bit of an edge-case.
------------------------------------------------------------------------
[2012-05-12 16:04:27] laruence@php.net
is a fork, so the socket fd you created will share to the child process,
when you unset the socket, the refcount of it will decrement, but still not
zero(child also ref to it). so~~
you can try:
<?php
$errno=0;
$errstr='';
$socket = stream_socket_server("tcp://0.0.0.0:4321", $errno, $errstr);
`
exec 3>&-
exec 4>&-
exec 5>&-
exec 6>&-
exec 7>&-
#you can add more
php /tmp/while.php >/dev/null &
`;
unset($socket);
echo lsof -i:4321;
------------------------------------------------------------------------
[2012-05-11 07:08:45] dark9 at rune dot ws
Description:
------------
pleses exec test script.
Test script:
---------------
******************************test.php**************************
#! /usr/bin/php
<?php
$errno=0;
$errstr='';
$socket = stream_socket_server("tcp://0.0.0.0:4321", $errno, $errstr);
$while=__DIR__.DIRECTORY_SEPARATOR.'while.php > /dev/null &';
$while;
unset($socket);
echo lsof -i:4321;
******************************test.php end**********************
******************************while.php**************************
#! /usr/bin/php
<?php
while(true){}
******************************while.php end**********************
Expected result:
----------------
****************************** first exec ******************************
root@ubuntu:~# ./test.php
****************************** second exec ******************************
root@ubuntu:~# ./test.php
Actual result:
--------------
****************************** first exec ******************************
root@ubuntu:~# ./test.php
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
while.php 29664 root 3u IPv4 61634581 0t0 TCP *:4321 (LISTEN)
****************************** second exec ******************************
root@ubuntu:~# ./test.php
PHP Warning: stream_socket_server(): unable to connect to tcp://0.0.0.0:4321
(Address already in use) in /root/test.php on line 5
Warning: stream_socket_server(): unable to connect to tcp://0.0.0.0:4321 (Address
already in use) in /root/test.php on line 5
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
while.php 29664 root 3u IPv4 61634581 0t0 TCP *:4321 (LISTEN)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62001&edit=1
Thread (4 messages)