Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
296 views
in Technique[技术] by (71.8m points)

PHP Ratchet websocket server. Memory leaks when a client with a low internet speed connects

I use the simple Ratchet server for sender-client communication. http://socketo.me/docs/troubleshooting

https://github.com/ratchetphp/Ratchet

My application class is very simple and it looks like this:

{
    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}
";
    }

    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
";
            }
        }
    }

    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
";
    }

    public function onError(ConnectionInterface $conn, Exception $e)
    {
        echo "An error has occurred: {$e->getMessage()}
";

        $conn->close();
    }
}

I'm just looking for solution to such problem: when a client with a low internet speed connects, the message queue overflows causing a memory leak in ram. I tried to find a place in code, where the message queue is stored for checking size of the queue and breaking connection with the problem user, but I did not succeed.

I would be glad for any decision.

question from:https://stackoverflow.com/questions/66065990/php-ratchet-websocket-server-memory-leaks-when-a-client-with-a-low-internet-spe

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...