GearmanWorker
class GearmanWorker (View source)
Class: GearmanWorker
Methods
Creates a GearmanWorker instance representing a worker that connects to the job server and accepts tasks to run.
Returns the last Gearman return code.
Returns an error string for the last error encountered.
Returns the value of errno in the case of a GEARMAN_ERRNO return value.
Gets the options previously set for the worker.
Sets one or more options to the supplied value.
Adds one or more options to the options previously set.
Removes (unsets) one or more worker options.
Returns the current time to wait, in milliseconds, for socket I/O activity.
Sets the interval of time to wait for socket I/O activity.
Give the worker an identifier so it can be tracked when asking gearmand for the list of available workers.
Adds a job server to this worker. This goes into a list of servers than can be used to run jobs. No socket I/O happens here.
Adds one or more job servers to this worker. These go into a list of servers that can be used to run jobs. No socket I/O happens here.
Causes the worker to wait for activity from one of the Gearman job servers when operating in non-blocking I/O mode. On failure, issues a E_WARNING with the last Gearman error encountered.
Registers a function name with the job server with an optional timeout. The timeout specifies how many seconds the server will wait before marking a job as failed. If the timeout is set to zero, there is no timeout.
Unregisters a function name with the job servers ensuring that no more jobs (for that function) are sent to this worker.
Unregisters all previously registered functions, ensuring that no more jobs are sent to this worker.
No description
Registers a function name with the job server and specifies a callback corresponding to that function. Optionally specify extra application context data to be used when the callback is called and a timeout.
Waits for a job to be assigned and then calls the appropriate callback function.
Details
__construct()
Creates a GearmanWorker instance representing a worker that connects to the job server and accepts tasks to run.
int
returnCode()
Returns the last Gearman return code.
string
error()
Returns an error string for the last error encountered.
int
getErrno()
Returns the value of errno in the case of a GEARMAN_ERRNO return value.
int
options()
Gets the options previously set for the worker.
bool
setOptions(int $option)
Sets one or more options to the supplied value.
bool
addOptions(int $option)
Adds one or more options to the options previously set.
bool
removeOptions(int $option)
Removes (unsets) one or more worker options.
int
timeout()
Returns the current time to wait, in milliseconds, for socket I/O activity.
bool
setTimeout(int $timeout)
Sets the interval of time to wait for socket I/O activity.
bool
setId(string $id)
Give the worker an identifier so it can be tracked when asking gearmand for the list of available workers.
bool
addServer(string $host = '127.0.0.1', int $port = 4730)
Adds a job server to this worker. This goes into a list of servers than can be used to run jobs. No socket I/O happens here.
bool
addServers(string $servers = '127.0.0.1:4730')
Adds one or more job servers to this worker. These go into a list of servers that can be used to run jobs. No socket I/O happens here.
bool
wait()
Causes the worker to wait for activity from one of the Gearman job servers when operating in non-blocking I/O mode. On failure, issues a E_WARNING with the last Gearman error encountered.
bool
register(string $function_name, int $timeout)
Registers a function name with the job server with an optional timeout. The timeout specifies how many seconds the server will wait before marking a job as failed. If the timeout is set to zero, there is no timeout.
bool
unregister(string $function_name)
Unregisters a function name with the job servers ensuring that no more jobs (for that function) are sent to this worker.
bool
unregisterAll()
Unregisters all previously registered functions, ensuring that no more jobs are sent to this worker.
grabJob()
No description
bool
addFunction(string $function_name, callable $function, mixed $context = null, int $timeout = 0)
Registers a function name with the job server and specifies a callback corresponding to that function. Optionally specify extra application context data to be used when the callback is called and a timeout.
bool
work()
Waits for a job to be assigned and then calls the appropriate callback function.
Issues an E_WARNING with the last Gearman error if the return code is not one of GEARMAN_SUCCESS, GEARMAN_IO_WAIT, or GEARMAN_WORK_FAIL.