Created
September 17, 2014 13:54
-
-
Save mathroc/7ab55a88162ac59cd299 to your computer and use it in GitHub Desktop.
Find unused port (cli - php)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
$address = '127.0.0.1'; | |
// Create a new socket | |
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | |
// Bind the source address | |
socket_bind($sock, $address); | |
socket_getsockname($sock, $address, $port); | |
echo $port; | |
socket_close($sock); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment