2013-01-19 46 views
0

機1 - 使用PHP API客戶端Gearman的工人不接收輸入

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

機2 - 使用PHP API,直接在bash - 工人
gearman -w -f demotask -- php -f taskexecutor.php

去,TaskExecutor越來越來看,但不包含hello world預期

附:對PHP的API和第二臺機器上的永久while循環不感興趣。我想Gearman的開始我的劇本時,它需要

回答

1

我真的不推薦此實現。如果有什麼錯在你的PHP腳本,你將無法重新提交作業,或Gearman的溝通。

Anwyays,問題是,當gearman client抓住工作,工作量傳遞給您的PHP進程的STDIN。因此,這意味着$ argv的是總是將是空的。您傳入的參數可以像這樣從STDIN中讀取;

$ PARAMS =與fgets(STDIN);

我建議你通過你的PARAMS爲JSON字符串,所以你可以使用簡單的功能,如json_encodejson_decode,而不必擔心結構或編碼太多,等

+0

是的,我只是想出一個剛纔它通過標準輸入。 – Alex