开发者

Only one gearman worker is getting jobs

开发者 https://www.devze.com 2023-03-23 17:39 出处:网络
I have a gearman worker written in PHP that echoes something and sleeps a few seconds. I started two instances of this worker and when a I now run gearman a couple of times to do that job only one of

I have a gearman worker written in PHP that echoes something and sleeps a few seconds. I started two instances of this worker and when a I now run gearman a couple of times to do that job only one of the workers (the last one that I started) is executed--never the other one although the client has to wait until this worker has finished his job. Am I doing something wrong here or is that the idea of how gearman should word?

# cat ./testworker.php 
<?php

$Worker = new \GearmanWorker;
$Worker->addServers('127.0.0.1:4730');
$Worker->addFunction('test', 'work');
while ($Worker->work() || $Worker->returnCode() == GEARMAN_TIMEOUT) {
        if ($Worker->returnCode() != GEARMAN_SUCCESS)
                break;
}

function work()
{
        echo getmypid();
        sleep(1);
}

Then I started the worker in two consoles with the command

# php ./testworker.php

Then I ran gearman to jun the job a couple of times:

# gearman -f test -s

Could it be that I need the -t option for the gearman daemon? I am working on OS-X.

# ps ax | grep gearman
4128  ??  Ss     0:00.02 /opt/local/bin/daemondo --label=gearmand --start-cmd /opt/local/sbin/gearman
4129  ??  S      0:00.04 /opt/local/sbin/gearmand -vv --port=4730 -u root --pid-file=/opt/local/var/r
4250  p5  S+     0:00.01 grep gearman

BTW: How can I change an开发者_C百科y options in a daemondo controlled process? I changed /opt/local/etc/LaunchDaemons/org.macports.gearmand/org.macports.gearmand.plist but I think I need to execute a commans that re-reads the list.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号