**一.PHP内置WEB服务器** #网站根目录为/php8,并且指定端口为8000 #默认首页为index.php ~~~ php -S 192.168.2.1:8000 -t /php8 ~~~ **二.新版本支持动态端口** ~~~ php -S 192.168.2.1:0 -t /php8 ~~~ **三.Socket也支持动态端口** 1.关闭display\_errors #php.ini ~~~ display_errors=Off ~~~ 2.测试socket使用动态端口 ~~~ $socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp')); socket_bind($socket,'192.168.2.1',0); socket_listen($socket); while(true){ $connection = socket_accept($socket); socket_getpeername($connection,$cip,$cport); $buffer = "Welcome To PHP8\n"; if($buffer != ""){ socket_write($connection,"{$buffer}\n"); } while($data = socket_read($connection, 1024,PHP_NORMAL_READ)){ $buffer = $data; printf("{$cip}:{$cport}-->{$buffer}\n"); socket_write($connection,"{$cip}:{$cport}-->{$buffer}\n"); } socket_close($connection); printf("{$cip}:{$cport} disconnected\n"); } ~~~