齿轮工人不接受输入

时间:2013-01-19 18:23:56

标签: php gearman

使用PHP api

计算机1 - 客户端

$client = new \GearmanClient();
$client->addServer(..);
$client->doBackground('demotask', 'hello world');

机器2 - 工作人员 - 使用PHP api,直接在bash中:
gearman -w -f demotask -- php -f taskexecutor.php

taskexecutor正在运行,$argv未按预期包含hello world

P.S。对PHP的API和第二台机器上永远的while循环不感兴趣。我希望gearman在需要时启动我的脚本

1 个答案:

答案 0 :(得分:1)

我真的不推荐这个实现。如果您的PHP脚本出现任何问题,您将无法重新提交作业或与齿轮工人沟通。

<\ n> Anwyays,问题是当gearman client抓取作业时,作业工作量会传递给php进程的STDIN。这意味着$ argv 始终将为空。您传入的参数可以像STDIN一样读取;

  

$ params = fgets(STDIN);

我建议您将params作为JSON字符串传递,这样您就可以使用json_encodejson_decode之类的简单函数,而不必过多担心结构或编码等。

相关问题