public GearmanTask GearmanClient::addTask ( string $function_name , string $workload [, mixed &$context [, string $unique ]] ) public bool GearmanWorker::addFunction ( string $function_name , callback $function [, mixed &$context [, int $timeout ]] )
These are class methods that can be used to integrate the two.
With these, how do you relate the workload with the called function?
GearmanClientis used to submit a task. Normally this is done from a web page, or a script meant to read a list of tasks to be submitted.GearmanWorkeris meant to be set up in such a way that many parallel ‘workers’ can be run at the same time. Logically, whatever a worker does should represent a single atomic unit of work. That can mean doing a single transformation of an object into another and saving it back to the database, or assembling and sending an html email for a single user.$function_nameis a function that takes a single argument, which is aGearmanJobobject.So, your controller script might look something like this.
Then, your worker will do something like this.
A few things to keep in mind:
whileloop. Make sure to set your timeout and memory limits appropriately.exit;PHP still sucks with memory usage, and it can be hard to tell when a worker will be killed because it ran out of memory.