php-reque: worker 失败 "MySQL server has gone away"
php-reque: worker fails with "MySQL server has gone away"
我开始使用 php-resque (https://github.com/chrisboulton/php-resque) 以及 php 和 mysql 服务器。我看到工人 "MySQL server has gone away" 错误。
作业排队代码:
if ($request->command == 'custom_script') {
//error_log("before queue");
Resque::enqueue($queue, 'AsyncTest', array('text'=>'yolo'));
//error_log("after queue");
}
工作class:
class AsyncTest{
public function setUp() {
# Set up something before perform, like establishing a database connection
$mysql = Mysql::getInstance();
EH::setErrorHandler();
}
public function perform()
{
// $mysql = Mysql::getInstance();
// EH::setErrorHandler();
//error_log($this->args['text']);
$haiku_step_query= $mysql->query("SELECT id FROM haiku LIMIT 10 OFFSET 1");
$row = $mysql->fetch_assoc($haiku_step_query);
$haiku_id = $row['id'];
}
public function tearDown() {
# Run after perform, like closing resources
}
}
我看到 "MySQL server has gone away" 条错误消息:
MySQL ERROR №2006 MySQL server has gone away[qs:SELECT id FROM haiku LIMIT 10 OFFSET 1]
(/var/www/html/haiku_server/vendor/chrisboulton/php-resque/resque.php line 77
Resque_Worker->work(5) >> /var/www/html/haiku_server/vendor/chrisboulton/php-resque/lib/Resque/Worker.php line 199
Resque_Worker->perform(Object) >> /var/www/html/haiku_server/vendor/chrisboulton/php-resque/lib/Resque/Worker.php line 237
Resque_Job->perform() >> /var/www/html/haiku_server/vendor/chrisboulton/php-resque/lib/Resque/Job.php line 182
AsyncTest->perform() >> /var/www/html/haiku_server/includes/bgJobs/AsyncThreads.php line 48
Mysql->query("SELECT id FROM haiku LIMIT 10 OFFSET 1") >> /var/www/html/haiku_server/includes/Mysql.class.php line 113 )
请注意,这不会发生,即 mysql 工作正常,当我执行没有 php-resque 的操作时,例如:
if ($request->command == 'custom_script') {
$mysql = Mysql::getInstance();
EH::setErrorHandler();
$haiku_step_query= $mysql->query("SELECT id FROM haiku LIMIT 10 OFFSET 1");
$row = $mysql->fetch_assoc($haiku_step_query);
$haiku_id = $row['id'];
}
看看这个问题:
https://github.com/chrisboulton/php-resque/issues/269
一个可能的原因是因为在作业第一次运行后,您的对象将保持加载在内存中,包括您的 MySQL 连接。解决方案是在执行方法中重新连接到 MySQL。
我开始使用 php-resque (https://github.com/chrisboulton/php-resque) 以及 php 和 mysql 服务器。我看到工人 "MySQL server has gone away" 错误。
作业排队代码:
if ($request->command == 'custom_script') {
//error_log("before queue");
Resque::enqueue($queue, 'AsyncTest', array('text'=>'yolo'));
//error_log("after queue");
}
工作class:
class AsyncTest{
public function setUp() {
# Set up something before perform, like establishing a database connection
$mysql = Mysql::getInstance();
EH::setErrorHandler();
}
public function perform()
{
// $mysql = Mysql::getInstance();
// EH::setErrorHandler();
//error_log($this->args['text']);
$haiku_step_query= $mysql->query("SELECT id FROM haiku LIMIT 10 OFFSET 1");
$row = $mysql->fetch_assoc($haiku_step_query);
$haiku_id = $row['id'];
}
public function tearDown() {
# Run after perform, like closing resources
}
}
我看到 "MySQL server has gone away" 条错误消息:
MySQL ERROR №2006 MySQL server has gone away[qs:SELECT id FROM haiku LIMIT 10 OFFSET 1]
(/var/www/html/haiku_server/vendor/chrisboulton/php-resque/resque.php line 77
Resque_Worker->work(5) >> /var/www/html/haiku_server/vendor/chrisboulton/php-resque/lib/Resque/Worker.php line 199
Resque_Worker->perform(Object) >> /var/www/html/haiku_server/vendor/chrisboulton/php-resque/lib/Resque/Worker.php line 237
Resque_Job->perform() >> /var/www/html/haiku_server/vendor/chrisboulton/php-resque/lib/Resque/Job.php line 182
AsyncTest->perform() >> /var/www/html/haiku_server/includes/bgJobs/AsyncThreads.php line 48
Mysql->query("SELECT id FROM haiku LIMIT 10 OFFSET 1") >> /var/www/html/haiku_server/includes/Mysql.class.php line 113 )
请注意,这不会发生,即 mysql 工作正常,当我执行没有 php-resque 的操作时,例如:
if ($request->command == 'custom_script') {
$mysql = Mysql::getInstance();
EH::setErrorHandler();
$haiku_step_query= $mysql->query("SELECT id FROM haiku LIMIT 10 OFFSET 1");
$row = $mysql->fetch_assoc($haiku_step_query);
$haiku_id = $row['id'];
}
看看这个问题: https://github.com/chrisboulton/php-resque/issues/269
一个可能的原因是因为在作业第一次运行后,您的对象将保持加载在内存中,包括您的 MySQL 连接。解决方案是在执行方法中重新连接到 MySQL。