我想为 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;
}
}