【发布时间】:2017-03-13 07:27:03
【问题描述】:
所以我是 web 套接字的新手,特别是 php,所以我尝试了这个名为 socketo.me 的帮助程序库。 一切正常,套接字连接获取消息,向所有客户端填充消息,但唯一的问题是它在我不知道的某个时间后超时。有一天我让套接字保持连接,第二天早上我来尝试连接,但它没有连接,我必须重新启动套接字(服务器继续运行)。 这是我用来运行套接字的代码。
public static function actioninitialize(){
$server = IoServer::factory(
new Chat(),
28
);
$server->run();
}
28 是我使用的端口,Chat() 是我用来接收和填充消息的消息接口
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})\n";
}
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\n";
}
public function onError(ConnectionInterface $conn, \Exception $e) {
echo "An error has occurred: {$e->getMessage()}\n";
$conn->close();
}
}
所以,我看到了他们的文档,但几乎找不到这个超时的东西来自哪里。我也看过 php 文档,看到了一些东西并尝试过,但没有任何帮助。 任何帮助将不胜感激。 谢谢。
【问题讨论】: