작은 웹 서버 스크립트가 있습니다. 'localhost'로 설정하면 외부에서 해당 포트로 텔넷 할 수 없습니다. FQDN으로 설정하면 다음과 같이 telnet 할 수 없습니다 : 'telnet localhost 7777'. 이 경우 호스트의 이름을 지정하는 올바른 방법은 무엇입니까?소켓 올바른 호스트 이름 PHP
$host = 'localhost';
$port = 7777;
set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");
while(1)
{
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
$input = socket_read($spawn, 1024) or die("Could not read input\n");
while(trim($input)!="")
{
$msg=$msg.$input;
$input = socket_read($spawn, 1024) or die("Could not read input\n");
}
$webserver = new Server($msg);
$output = $webserver->response();
unset($msg);
socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");
socket_close($spawn);
}
전체 웹 서버를 PHP로 작성하고 있습니까? 일반적으로 아파치, nginx 등과 같은 것을 실제 웹 서버로 사용하며, PHP는 컨텐츠를 제공하는 책임을집니다. – Thanatos