制作 PHP-websocket 服务器时网关超时错误

问题描述

我正在尝试用 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...