class GearmanWorker (View source)

Class: GearmanWorker

Methods

__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.

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.

Return Value

int

A valid Gearman return code

string error()

Returns an error string for the last error encountered.

Return Value

string

An error string

int getErrno()

Returns the value of errno in the case of a GEARMAN_ERRNO return value.

Return Value

int

A valid errno

int options()

Gets the options previously set for the worker.

Return Value

int

The options currently set for the worker

bool setOptions(int $option)

Sets one or more options to the supplied value.

Parameters

int $option

The options to be set

Return Value

bool

Always returns true

bool addOptions(int $option)

Adds one or more options to the options previously set.

Parameters

int $option

The options to be added

Return Value

bool

Always returns true

bool removeOptions(int $option)

Removes (unsets) one or more worker options.

Parameters

int $option

The options to be removed (unset)

Return Value

bool

Always returns true

int timeout()

Returns the current time to wait, in milliseconds, for socket I/O activity.

Return Value

int

A time period is milliseconds. A negative value indicates an infinite timeout

bool setTimeout(int $timeout)

Sets the interval of time to wait for socket I/O activity.

Parameters

int $timeout

An interval of time in milliseconds. A negative value indicates an infinite timeout

Return Value

bool

Always returns true

bool setId(string $id)

Give the worker an identifier so it can be tracked when asking gearmand for the list of available workers.

Parameters

string $id

A string identifier

Return Value

bool

Returns TRUE on success or FALSE on failure

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.

Parameters

string $host
int $port

Return Value

bool

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.

Parameters

string $servers

A comma separated list of job servers in the format host:port. If no port is specified, it defaults to 4730

Return Value

bool

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.

Return Value

bool

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.

Parameters

string $function_name

The name of a function to register with the job server

int $timeout

An interval of time in seconds

Return Value

bool

A standard Gearman return value

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.

Parameters

string $function_name

The name of a function to register with the job server

Return Value

bool

A standard Gearman return value

bool unregisterAll()

Unregisters all previously registered functions, ensuring that no more jobs are sent to this worker.

Return Value

bool

A standard Gearman return value

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.

Parameters

string $function_name

The name of a function to register with the job server

callable $function

A callback that gets called when a job for the registered function name is submitted

mixed $context

A reference to arbitrary application context data that can be modified by the worker function

int $timeout

An interval of time in seconds

Return Value

bool

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.

Return Value

bool