Recently in doing a learning app API work, some of the statistical aspects of MySQL naturally handed to the queue to deal with, yesterday, a migration database found some papers information job server did not receive, may be because the paper problem is a large number of reasons, resulting in Gearman work blocked, so Gearman Log is not generated, indicating that it did not accept the task at all.
The original code is
Client:
//use of the Do series$client=New\gearmanclient ();$client-addserver ();$client->dobackground ("Stat", Json_encode (Array(' stat ' =$stat, ' item_list ' =$item _detail)));//asynchronous worker process, return processing work ID$client- Do("Stat", Json_encode (Array(' stat ' =$stat, ' item_list ' =$item _detail)));//synchronizes the worker process and returns the return value of the work function
Service side:
$worker=NewGearmanworker ();$worker-addserver ();//accept the client's stat task and pass it to the Study_stat function$worker->addfunction ("stat", "Study_stat");//Endless cycle operation, gearman internal processing, there will be no high consumption of dead while($worker-Work ());functionStudy_stat ($job) { $data= Json_decode ($job->workload (),true); //handling Code omission}
Normal use is no problem, but the beginning of yesterday will appear not to accept the task of the situation. So this morning I replaced the queue, the code is as follows:
Client:
$client New \gearmanclient (); $client->addserver (' 127.0.0.1 ', 4730); $client->addtaskbackground ("Stat", Json_encode (' stat ' =$stat, ' item_list ' =$item _detail))); // Asynchronous queues
$client->addtask ("Stat", Json_encode (' stat ' = $stat, ' item_list ' + $item _detail));//sync queue
$client->runtasks ();//Run tasks in queue, just do series do not need Runtask ()
Service side:
$worker New Gearmanworker (); $worker->addserver (' 127.0.0.1 ', 4730); $worker->addfunction ("stat",function$job) { $data = Json_ Decode ($job->workload (),true); // accept the passed JSON
Handling Code omission
}
Specifically added the server IP and port, to prevent errors, and then tested again, there is no problem. New knowledge learned in the future using Gearman will also be written here.
Working experience of Gearman Job server