PHP: Can I use stream_socket_server to get free tcp port of the server

When you specify port to 0 stream_socket_server(“tcp://xx.xx.xx.xx:0“), you can get the unused port. It works perfectly when I pass localhost as an IP, but when I try to get an unused port of a remote server I keep getting Unable to connect to tcp://xx.xx.xx.xx:0 (Cannot assign requested address).

Is there something am I missing? Is it even possible to use it in such a way?