mercredi 27 janvier 2016

gearman php callback,how to use the gearman

I has the problem like this: Now I need to use the PHP to call the gearman to download the picture async and give it my callback function.And when it done its job,the gearman will return me the data by using my callback function.(My first time to use the gearman) the problem is that:when I call the doBackGround,and echo the $result,it return the info:"H:ip:xxx.xxx.xxx.xxx:number",it seems work,but the file I create in the callback function can not find in my web service.I do not where is wrong? in PHP,how can I make the code work?these are my code:

    public function tryGearman() {
    $url = "url1\n";
    $url1 = "url2\n";
    $url2 = "url3\n";

    $urlFile = fopen("url.txt","w") or die("can not open the file");
    fwrite($urlFile,$url);
    fwrite($urlFile,$url1);
    fwrite($urlFile,$url2);
    fclose($urlFile);

    $gmclient = new GearmanClient();

    $gmclient->addServer();

    $gmclient->setCompleteCallback('getProData');

    $result = $gmclient->doBackground('upload','{"callback_url":"https://my_web_app_realm_name/index.php?c=Game&a=getProData","input_file":"/usr/local/test/url.txt"}');

    echo $result;
}

public function getProData($data) {
    $urlFile = fopen("result.txt","w") or die("can not open the file");
    fwrite($urlFile,$data);
    fclose($urlFile);
}




Aucun commentaire:

Enregistrer un commentaire