clients = new \SplObjectStorage(); $this->loop = $loop; } public function onOpen(ConnectionInterface $conn) { $this->clients->attach($conn); } public function onMessage(ConnectionInterface $from, $msg) { $from->send($msg); $this->loop->addTimer(Timer::MIN_INTERVAL * 10, function() use ($from) { sleep(5); $from->send('Proceeded!'); }); } public function onClose(ConnectionInterface $conn) { $this->clients->detach($conn); } public function onError(ConnectionInterface $conn, \Exception $e) { $conn->close(); } } $loop = \React\EventLoop\Factory::create(); // Run the server application through the WebSocket protocol on port 4430 $app = new Ratchet\App('crawler.yt.lemnoslife.com', 4430, '127.0.0.1', $loop); $app->route('/websocket', new MyChat($loop), array('*')); $app->run();