我想为Gearman作业设置超时持续时间。例如,我不希望齿轮工作的运行时间超过30秒,如果工作运行超过30秒,则应停止工作并开始下一个工作。
Gearman可以吗? (我在Centos 6.2上使用Gearman PHP API)
答案 0 :(得分:2)
您要找的是GearmanWorker::timeout这里是Good Example
//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;
}
}