问题描述
我使用简单的 Ratchet 服务器进行发送方-客户端通信。 http://socketo.me/docs/troubleshooting
https://github.com/ratchetphp/Ratchet
我的应用程序类非常简单,如下所示:
{
protected $clients;
public function __construct()
{
$this->clients = new \SplObjectStorage;
}
public function onopen(ConnectionInterface $conn)
{
$this->clients->attach($conn);
$connect_time = date("Y-m-d H:i:s");
echo "[{$connect_time}] New connection! IP:{$conn->remoteAddress}:{$conn->remotePort}\n";
}
public function onMessage(ConnectionInterface $from,$msg)
{
foreach ($this->clients as $client) {
if ($from !== $client) {
$client->send($msg);
var_dump($this->clients->current());
$msg_get_time = date("Y-m-d H:i:s");
echo "[{$msg_get_time}] message was received and sent to clients\n";
}
}
}
public function onClose(ConnectionInterface $conn)
{
$this->clients->detach($conn);
$disconnect_time = date("Y-m-d H:i:s");
echo "[{$disconnect_time}] Connection {$conn->remoteAddress} has disconnected\n";
}
public function onError(ConnectionInterface $conn,\Exception $e)
{
echo "An error has occurred: {$e->getMessage()}\n";
$conn->close();
}
}
我只是在寻找解决此类问题的方法:当互联网速度较低的客户端连接时,消息队列溢出导致内存泄漏。 我试图在代码中找到一个存储消息队列的地方,用于检查队列大小并断开与问题用户的连接,但没有成功。
我很乐意做出任何决定。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)