ini_set('memory_limit', '1G');
$gmworker= new GearmanWorker();
$gmworker->addServer();
$gmworker->addFunction("create_job_process", "worker_create_job");
$gmworker->setTimeout(-1);
print "Waiting for job...n";
while($gmworker->work())
{
if ($gmworker->returnCode() != GEARMAN_SUCCESS)
{
echo "return_code: " . $gmworker->returnCode() . "n";
break;
}
if ($gmworker->returnCode() == GEARMAN_SUCCESS)
{
echo "successnn";
break;
}
sleep(1);
}
当日志显示"成功"时,我可以看到内存使用在增长,然后得到错误:
PHP致命错误:允许的内存大小为1073741824字节耗尽(尝试分配24字节)
if ($ret == GEARMAN_SUCCESS)
{
echo "successn";
//force to quit
exec("kill -9 ". getmypid());
die();
}
最后添加了exec("kill -9 ")。getmypid ());