Created
October 25, 2018 05:19
-
-
Save axgle/af1f2224900f8764b83ad7225a80ca77 to your computer and use it in GitHub Desktop.
get valid random socket port with 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
<?php | |
//get valid random socket port with php | |
$s = stream_socket_server("tcp://localhost:0"); | |
$ss = stream_socket_get_name($s,0); | |
$pos = | |
strrpos($ss,":"); | |
$p = substr($ss,$pos+1); | |
fclose($s); | |
//$p+=1; | |
echo "http://localhost:$p\n"; | |
exec("php -S localhost:$p"); | |
//var_dump($ss); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment