Symfony4: Gos Websocket Error: MySQL server has gone away
Symfony4: Gos Websocket Error: MySQL server has gone away
我已经为 GOS:WebSocketBundle 启用了 PDO Periodic Pings,我仍然不时收到此错误:
09:41:28 ERROR [websocket] Connection error occurred Warning: Error
while sending QUERY packet. PID=30536 in /home/dev.symfony/libs/composer_vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php
10:00:23 ERROR [websocket] Connection error occurred
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in
/home/dev.symfony/libs/composer_vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php
line 107 ["connection_id" => 3365,"session_id" =>
"11667050395acf121709d30728596936"] []
还有一点就是,如果没有人使用开发服务器,在日志中没有错误,但是如果我立即登录就会出现这个错误。
github https://github.com/GeniusesOfSymfony/WebSocketBundle/issues/299 上也已打开问题
但没有答案,所以我也在这里问。谢谢。
已解决。问题是我在 "onSubscribe" 函数内的 Topic 内定义了周期性计时器,例如:
public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
{
...
$topicTimer = $connection->PeriodicTimer;
//Add periodic timer every 3 seconds update
$topicTimer->addPeriodicTimer('notifications', 3, function() use ($topic, $connection) {
$user = $this->clientManipulator->getClient($connection);
if($user) {
$counters = $this->globalVariables->getCounters($user);
$connection->event($topic->getId(),['msg' => $counters]);
}
});
...
}
但现在我切换到 "standalone" 定期,就像这里描述的那样 https://github.com/GeniusesOfSymfony/WebSocketBundle/blob/master/Periodic/PdoPeriodicPing.php
并将其附加到 websocket。现在数据库没有超时。
值得注意的是,当您按照 Symfony 文档创建 PdoSessionHandler http://symfony.com/doc/current/doctrine/pdo_session_storage.html where you are passing the dsn instead of pdo service it won't work, because the session handler will create other connection. To solve this create a pdo service and pass it to the PdoSessionHandler like it is described in the https://github.com/GeniusesOfSymfony/WebSocketBundle/blob/master/Resources/docs/SessionSetup.md
我已经为 GOS:WebSocketBundle 启用了 PDO Periodic Pings,我仍然不时收到此错误:
09:41:28 ERROR [websocket] Connection error occurred Warning: Error
while sending QUERY packet. PID=30536 in /home/dev.symfony/libs/composer_vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php
10:00:23 ERROR [websocket] Connection error occurred
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in
/home/dev.symfony/libs/composer_vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php
line 107 ["connection_id" => 3365,"session_id" =>
"11667050395acf121709d30728596936"] []
还有一点就是,如果没有人使用开发服务器,在日志中没有错误,但是如果我立即登录就会出现这个错误。
github https://github.com/GeniusesOfSymfony/WebSocketBundle/issues/299 上也已打开问题 但没有答案,所以我也在这里问。谢谢。
已解决。问题是我在 "onSubscribe" 函数内的 Topic 内定义了周期性计时器,例如:
public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
{
...
$topicTimer = $connection->PeriodicTimer;
//Add periodic timer every 3 seconds update
$topicTimer->addPeriodicTimer('notifications', 3, function() use ($topic, $connection) {
$user = $this->clientManipulator->getClient($connection);
if($user) {
$counters = $this->globalVariables->getCounters($user);
$connection->event($topic->getId(),['msg' => $counters]);
}
});
...
}
但现在我切换到 "standalone" 定期,就像这里描述的那样 https://github.com/GeniusesOfSymfony/WebSocketBundle/blob/master/Periodic/PdoPeriodicPing.php 并将其附加到 websocket。现在数据库没有超时。
值得注意的是,当您按照 Symfony 文档创建 PdoSessionHandler http://symfony.com/doc/current/doctrine/pdo_session_storage.html where you are passing the dsn instead of pdo service it won't work, because the session handler will create other connection. To solve this create a pdo service and pass it to the PdoSessionHandler like it is described in the https://github.com/GeniusesOfSymfony/WebSocketBundle/blob/master/Resources/docs/SessionSetup.md