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