【发布时间】:2017-02-07 06:11:44
【问题描述】:
当我在单个服务器上运行 gearman 时,最多三个工作人员工作正常,但当我启动第四个时,一个 php 代码工作正常,但无法检测到新工作人员,也没有清除作业队列。
protected function createWorker()
{
$this->worker = new \GearmanWorker();
$config = $this->app->config->job_remote;
$this->worker->addServer($config['host'], $config['port']);
return $this->worker;
}
public function listen($eventType, $callback)
{
if (!($this->worker instanceof \GearmanWorker)){
$this->worker = $this->createWorker();
}
$this->worker->addFunction($eventType, $callback);
return $this->worker;
}
public function doWork($worker)
{
if (!($worker instanceof \GearmanWorker)){
$worker = $this->createWorker();
}
$this->worker = $worker;
while (1) {
$this->worker->work();
$this->app->log->debug($this->worker->returnCode());
if ($this->worker->returnCode() != \GEARMAN_SUCCESS) {
break;
}
}
}
首先我调用“listen”方法,然后调用“doWork”方法
客户端代码:
protected function createClient()
{
$this->client = new \GearmanClient();
$config = $this->app->config->job_remote;
$this->client->addServer($config['host'], $config['port']);
return $this->client;
}
public function addTask($eventType, array $params)
{
if (!($this->client instanceof \GearmanClient)){
$this->client = $this->createClient();
}
// add single task in queue
$this->client->addTaskBackground($eventType, serialize($params));
// Run task
$this->client->runTasks();
}
【问题讨论】:
-
你的代码在哪里......你尝试了什么
-
我已经添加了代码现在检查
-
您的客户代码在哪里???从你分配工作的地方。
-
伙计,最多 3 名工人,一切正常。
-
我正在使用 GearmanManager,目前正在从事该项目,我最多可以工作 50 名工人。即使我尝试了 100 名工人,它也工作得很好,只是它挂了我的电脑..
标签: php web-worker gearman