Working experience of Gearman Job server

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.