So I'm new in web sockets specially in php so i tried this helper library called socketo.me. Every thing works fine socket connects gets messages, populates messages to all clients but only problem is it gets timed out after sometime that i dont know. One day i leave socket connected and the very next morning I come and try to connect and its not connecting and i have to restart socket (Server keeps running). Here is the code im using to run socket.
public static function actioninitialize(){
$server = IoServer::factory(
new Chat(),
28
);
$server->run();
}
28 is the port im using and Chat() is the message interface im using to receive and populate messages
class Chat implements MessageComponentInterface {
protected $clients;
public function __construct() {
$this->clients = new \SplObjectStorage;
}
public function onOpen(ConnectionInterface $conn) {
// Store the new connection to send messages to later
$this->clients->attach($conn);
echo "New connection! ({$conn->resourceId})
";
}
public function onMessage(ConnectionInterface $from, $msg) {
foreach ($this->clients as $client) {
$client->send('eg' );
}
}
public function onClose(ConnectionInterface $conn) {
// The connection is closed, remove it, as we can no longer send it messages
$this->clients->detach($conn);
echo "Connection {$conn->resourceId} has disconnected
";
}
public function onError(ConnectionInterface $conn, \Exception $e) {
echo "An error has occurred: {$e->getMessage()}
";
$conn->close();
}
}
So, iv seen their documentation and all but couldnt find where is this timeout thing coming from. I have seen php documentation aswell and saw some things and tried but nothing helped. Any help will be appreciated. Thanks.