问题描述
我正在尝试用 PHP 制作一个 websocket 服务器。但是我在 Nginx/1.18.0 上收到 HTTP 504 网关超时错误消息。我正在使用 PHP7.4 我制作服务器的代码:
<?PHP
echo "<h1> PHP Socket Server </h1>";
#aim: To develop make a server that reverse the string sent by client using socket programming
#step 1: Set variable such as host and port
$host = "127.0.0.1";
$port = "1500";
// no timeout
set_time_limit(0);
#step 2: Create a socket
$socket = socket_create(AF_INET,SOCK_STREAM,0) or die("Could not create a server <br>");
#step 3: bind socket to the port and host
$bind_result = socket_bind($socket,$host,$port);
#step 4: start listening to the socket
$listen = socket_listen($socket,3) or die("Could not set up socket listener <br>");
#step 5: accept incoming connection
$spawn = socket_accept($socket) or die("Could not accept incoming connection<br>");
// Here $span is that socket resource which is actually responsive for communcation with client socket
#step 6: read the message from client socket
$message = socket_read($spawn,1024) or die("Cound not read message from client socket <br>");
#step 7: reverse the message
$reply = strrev($message);
#step 8: sending message to the client socket
socket_write($spawn,$reply,strlen($reply)) or die("Could not reply to the client socket <br>");
#step 9: close the socket
socket_close($spawn);
socket_close($socket);
?>
这里有什么问题?我错过了什么?我是否必须在 PHP 中安装任何扩展..... 我该如何解决这个问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)