Edit report at https://bugs.php.net/bug.php?id=62001&edit=1

 ID:                 62001
 Updated by:         larue...@php.net
 Reported by:        dark9 at rune dot ws
 Summary:            socket don't close
-Status:             Open
+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:

` ` 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`;


Previous Comments:
------------------------------------------------------------------------
[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

Reply via email to