0
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 "success\n\n";
    break;
  }
  sleep(1);
}

当日志中显示“成功”时,我可以看到内存使用量在增长,然后出现错误:

PHP致命错误:允许的内存大小为1073741824字节已用尽(试图分配24字节)

4

1 回答 1

1
  if ($ret == GEARMAN_SUCCESS)
  {
    echo "success\n";
    //force to quit
    exec("kill -9 ". getmypid());
    die();
  }

最后添加了 exec("kill -9 ".getmypid()); 停止该过程。

于 2011-08-02T05:39:25.930 回答