note 94749 modified in function.stream-socket-server by danbrown
| From: | danbrown@php.net | Date: | Mon, 23 Nov 2009 15:35:04 +0000 |
| Subject: | note 94749 modified in function.stream-socket-server by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-163198@lists.php.net to get a copy of this message | ||
In some specialized scenarios, you may want to create an AF_INET socket (UDP or TCP) but let the
system select an unused port for you. This is a standard feature of internet sockets but it
doesn't seem to be documented how to do this for the stream_socket_server function. It appears
you can get this behavior by selecting zero for the port number, for example, my test below printed
"127.0.0.1:4960".
<?php
$sock = stream_socket_server("udp://127.0.0.1:0");
$name = stream_socket_get_name($sock);
echo $name;
?>
--was--
In some specialized scenarios, you may want to create an AF_INET socket (UDP or TCP) but let the
system select an unused port for you. This is a standard feature of internet sockets but it
doesn't seem to be documented how to do this for the stream_socket_server function. It appears
you can get this behavior by selecting zero for the port number, for example, my test below printed
"127.0.0.1:4960".
$sock = stream_socket_server("udp://127.0.0.1:0");
$name = stream_socket_get_name($sock);
echo $name;
http://php.net/manual/en/function.stream-socket-server.php