我想为 Gearman 作业设置超时时间。例如,我不希望 gearman 作业运行超过 30 秒,如果作业运行超过 30 秒,则应该停止它并启动下一个作业。
Gearman可以做到这一点吗?(我在 Centos 6.2 上使用 Gearman PHP API)
您正在寻找的是GearmanWorker::timeout这是一个很好的例子
//Set Timeout
$gmworker->setTimeout(5000);
echo "Waiting for job...\n";
// Start working
while ( @$gmworker->work() || $gmworker->returnCode() == GEARMAN_TIMEOUT ) {
if ($gmworker->returnCode() == GEARMAN_TIMEOUT) {
// Normally one would want to do something useful here ...
continue;
}
if ($gmworker->returnCode() != GEARMAN_SUCCESS) {
// Somthign failed
break;
}
}