note 106006 added to function.socket-create-listen
| From: | w_barath at hotmail dot com | Date: | Sun, 02 Oct 2011 12:32:47 +0000 |
| Subject: | note 106006 added to function.socket-create-listen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183585@lists.php.net to get a copy of this message | ||
re vicente dot lopez at caixadesoft dot es's post below
The reason only the last port remains bound is because of PHP's automatic garbage collection.
$sock is a reference to a resource. When you re-use $sock then the refcount on the resource drops to
zero and it is destroyed.
This is great because we can write very simple and lazy code, but we also have to be careful to
preserve the resources we mean to keep using:
foreach($services as $port => $daemon){
if ($sock = @socket_create_listen($port)){
//$sockets[$sock] = $daemon; // using $sock as a key does not preserve it.
$sockets[$daemon] = $sock; // saving it as a value does!
} else {
echo("error\n");
}
}
----
Server IP: 69.147.83.197
Probable Submitter: 96.50.58.182
----
Manual Page -- http://www.php.net/manual/en/function.socket-create-listen.php
Edit -- https://master.php.net/note/edit/106006
Del: integrated -- https://master.php.net/note/delete/106006/integrated
Del: useless -- https://master.php.net/note/delete/106006/useless
Del: bad code -- https://master.php.net/note/delete/106006/bad+code
Del: spam -- https://master.php.net/note/delete/106006/spam
Del: non-english -- https://master.php.net/note/delete/106006/non-english
Del: in docs -- https://master.php.net/note/delete/106006/in+docs
Del: other reasons-- https://master.php.net/note/delete/106006
Reject -- https://master.php.net/note/reject/106006
Search -- https://master.php.net/manage/user-notes.php