我想检查一下 Gearman 守护进程是否正在运行。然后才运行任务,这样我的应用程序就不会崩溃。
这是我的代码:
$daemonRunning = true;
while( true )
{
try
{
Yii::app()->gearman->client->ping( true );
if ( $daemonRunning === false )
{
echo "Daemon back online. Starting signature process...\n";
}
Yii::app()->gearman->client->runTasks();
}
catch( GearmanException $e )
{
echo "Daemon appears to be down. Waiting for it to come back up...\n";
$daemonRunning = false;
}
sleep(1);
}
但问题是它ping
不会抛出异常,它会抛出一个致命错误:
PHP Error[2]: GearmanClient::ping(): flush(GEARMAN_COULD_NOT_CONNECT) 127.0.0.1:4730 -> libgearman/connection.cc:673
虽然奇怪的是,如果我删除ping
, and use only runTasks
,则会引发异常。
有关的:
当进程运行时 Gearman 守护进程关闭时,我该如何处理错误?当我关闭 Gearman 守护程序时,我从 PHP 收到以下错误:
php: libgearman/universal.cc:481: gearman_return_t connection_loop(gearman_universal_st&, const gearman_packet_st&, Check&): Assertion `&con->_packet == universal.packet_list' failed.
Aborted (core dumped)