|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-05-11 07:08 UTC] 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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 17:00:01 2025 UTC |
` ` 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`;