class GearmanClient (View source)

Class: GearmanClient

Methods

__construct()

Creates a GearmanClient instance representing a client that connects to the job server and submits tasks to complete.

int
returnCode()

Returns the last Gearman return code.

string
error()

Returns an error string for the last error encountered.

int
getErrno()

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

options()

No description

bool
setOptions(int $options)

Sets one or more client options.

bool
addOptions(int $options)

Adds one or more options to those already set.

bool
removeOptions(int $options)

Removes (unsets) one or more options.

int
timeout()

Returns the timeout in milliseconds to wait for I/O activity.

bool
setTimeout(int $timeout)

Sets the timeout for socket I/O activity.

string
context()

Get the application context previously set with GearmanClient::setContext.

bool
setContext(string $context)

Sets an arbitrary string to provide application context that can later be retrieved by GearmanClient::context.

bool
addServer(string $host = '127.0.0.1', int $port = 4730)

Adds a job server to a list of servers that can be used to run a task. No socket I/O happens here; the server is simply added to the list.

bool
addServers(string $servers = '127.0.0.1:4730')

Adds a list of job servers that can be used to run a task. No socket I/O happens here; the servers are simply added to the full list of servers.

wait()

No description

string
doHigh(string $function_name, string $workload, string|null $unique = null)

Runs a single high priority task and returns a string representation of the result. It is up to the GearmanClient and GearmanWorker to agree on the format of the result. High priority tasks will get precedence over normal and low priority tasks in the job queue.

string
doNormal(string $function_name, string $workload, string|null $unique = null)

Runs a single task and returns a string representation of the result. It is up to the GearmanClient and GearmanWorker to agree on the format of the result. Normal and high priority tasks will get precedence over low priority tasks in the job queue.

string
doLow(string $function, string $workload, string|null $unique = null)

Runs a single low priority task and returns a string representation of the result. It is up to the GearmanClient and GearmanWorker to agree on the format of the result. Normal and high priority tasks will get precedence over low priority tasks in the job queue.

string
doJobHandle()

Gets that job handle for a running task. This should be used between repeated GearmanClient::do calls. The job handle can then be used to get information on the task.

array
doStatus()

Returns the status for the running task. This should be used between repeated GearmanClient::do calls.

string
doBackground(string $function, string $workload, string|null $unique = null)

Runs a task in the background, returning a job handle which can be used to get the status of the running task.

string
doHighBackground(string $function, string $workload, string|null $unique = null)

Runs a high priority task in the background, returning a job handle which can be used to get the status of the running task. High priority tasks take precedence over normal and low priority tasks in the job queue.

string
doLowBackground(string $function, string $workload, string|null $unique = null)

Runs a low priority task in the background, returning a job handle which can be used to get the status of the running task. Normal and high priority tasks take precedence over low priority tasks in the job queue.

array
jobStatus(string $job_handle)

Object oriented style (method):.

GearmanTask|false
addTask(string $function_name, string $workload, mixed $context = null, string|null $unique = null)

Adds a task to be run in parallel with other tasks. Call this method for all the tasks to be run in parallel, then call GearmanClient::runTasks to perform the work. Note that enough workers need to be available for the tasks to all run in parallel.

GearmanTask|false
addTaskHigh(string $function_name, string $workload, mixed $context = null, string|null $unique = null)

Adds a high priority task to be run in parallel with other tasks. Call this method for all the high priority tasks to be run in parallel, then call GearmanClient::runTasks to perform the work. Tasks with a high priority will be selected from the queue before those of normal or low priority.

GearmanTask|false
addTaskLow(string $function_name, string $workload, mixed $context = null, string|null $unique = null)

Adds a low priority background task to be run in parallel with other tasks. Call this method for all the tasks to be run in parallel, then call GearmanClient::runTasks to perform the work. Tasks with a low priority will be selected from the queue after those of normal or low priority.

GearmanTask|false
addTaskBackground(string $function_name, string $workload, mixed $context = null, string|null $unique = null)

Adds a background task to be run in parallel with other tasks. Call this method for all the tasks to be run in parallel, then call GearmanClient::runTasks to perform the work.

GearmanTask|false
addTaskHighBackground(string $function_name, string $workload, mixed $context = null, string|null $unique = null)

Adds a high priority background task to be run in parallel with other tasks.

GearmanTask|false
addTaskLowBackground(string $function_name, string $workload, mixed $context = null, string|null $unique = null)

Adds a low priority background task to be run in parallel with other tasks. Call this method for all the tasks to be run in parallel, then call GearmanClient::runTasks to perform the work. Tasks with a low priority will be selected from the queue after those of normal or high priority.

addTaskStatus(string $job_handle, string $context = null)

Used to request status information from the Gearman server, which will call the specified status callback (set using GearmanClient::setStatusCallback).

bool
setWorkloadCallback(callable $callback)

Sets a function to be called when a worker needs to send back data prior to job completion. A worker can do this when it needs to send updates, send partial results, or flush data during long running jobs. The callback should accept a single argument, a GearmanTask object.

bool
setCreatedCallback(string $callback)

Sets a function to be called when a task is received and queued by the Gearman job server. The callback should accept a single argument, a GearmanClient oject.

bool
setDataCallback(callable $callback)

Sets the callback function for accepting data packets for a task. The callback function should take a single argument, a GearmanTask object.

bool
setWarningCallback(callable $callback)

Sets a function to be called when a worker sends a warning. The callback should accept a single argument, a GearmanTask object.

bool
setStatusCallback(callable $callback)

Sets a callback function used for getting updated status information from a worker. The function should accept a single argument, a GearmanTask object.

bool
setCompleteCallback(callable $callback)

Use to set a function to be called when a task is completed. The callback function should accept a single argument, a GearmanTask oject.

bool
setExceptionCallback(callable $callback)

Specifies a function to call when a worker for a task sends an exception.

bool
setFailCallback(callable $callback)

Sets the callback function to be used when a task does not complete successfully. The function should accept a single argument, a GearmanTask object.

bool
clearCallbacks()

Clears all the task callback functions that have previously been set.

bool
runTasks()

For a set of tasks previously added with GearmanClient::addTask, GearmanClient::addTaskHigh, GearmanClient::addTaskLow, GearmanClient::addTaskBackground, GearmanClient::addTaskHighBackground, or GearmanClient::addTaskLowBackground, this call starts running the tasks in parallel.

bool
ping(string $workload)

Sends some arbitrary data to all job servers to see if they echo it back.

Details

__construct()

Creates a GearmanClient instance representing a client that connects to the job server and submits tasks to complete.

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

A human readable error string

int getErrno()

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

Return Value

int

A valid Gearman errno

options()

No description

bool setOptions(int $options)

Sets one or more client options.

Parameters

int $options

The options to be set

Return Value

bool

Always returns true

bool addOptions(int $options)

Adds one or more options to those already set.

Parameters

int $options

The options to add

Return Value

bool

Always returns true

bool removeOptions(int $options)

Removes (unsets) one or more options.

Parameters

int $options

The options to be removed (unset)

Return Value

bool

Always returns true

int timeout()

Returns the timeout in milliseconds to wait for I/O activity.

Return Value

int

Timeout in milliseconds to wait for I/O activity. A negative value means an infinite timeout

bool setTimeout(int $timeout)

Sets the timeout for socket I/O activity.

Parameters

int $timeout

An interval of time in milliseconds

Return Value

bool

Always returns true

string context()

Get the application context previously set with GearmanClient::setContext.

Return Value

string

The same context data structure set with GearmanClient::setContext

bool setContext(string $context)

Sets an arbitrary string to provide application context that can later be retrieved by GearmanClient::context.

Parameters

string $context

Arbitrary context data

Return Value

bool

Always returns true

bool addServer(string $host = '127.0.0.1', int $port = 4730)

Adds a job server to a list of servers that can be used to run a task. No socket I/O happens here; the server is simply added to the list.

Parameters

string $host
int $port

Return Value

bool

bool addServers(string $servers = '127.0.0.1:4730')

Adds a list of job servers that can be used to run a task. No socket I/O happens here; the servers are simply added to the full list of servers.

Parameters

string $servers

A comma-separated list of servers, each server specified in the format host:port

Return Value

bool

wait()

No description

string doHigh(string $function_name, string $workload, string|null $unique = null)

Runs a single high priority task and returns a string representation of the result. It is up to the GearmanClient and GearmanWorker to agree on the format of the result. High priority tasks will get precedence over normal and low priority tasks in the job queue.

Parameters

string $function_name
string $workload
string|null $unique

Return Value

string

A string representing the results of running a task

string doNormal(string $function_name, string $workload, string|null $unique = null)

Runs a single task and returns a string representation of the result. It is up to the GearmanClient and GearmanWorker to agree on the format of the result. Normal and high priority tasks will get precedence over low priority tasks in the job queue.

Parameters

string $function_name
string $workload
string|null $unique

Return Value

string

A string representing the results of running a task

string doLow(string $function, string $workload, string|null $unique = null)

Runs a single low priority task and returns a string representation of the result. It is up to the GearmanClient and GearmanWorker to agree on the format of the result. Normal and high priority tasks will get precedence over low priority tasks in the job queue.

Parameters

string $function
string $workload
string|null $unique

Return Value

string

A string representing the results of running a task

string doJobHandle()

Gets that job handle for a running task. This should be used between repeated GearmanClient::do calls. The job handle can then be used to get information on the task.

Return Value

string

The job handle for the running task

array doStatus()

Returns the status for the running task. This should be used between repeated GearmanClient::do calls.

Return Value

array

An array representing the percentage completion given as a fraction, with the first element the numerator and the second element the denomintor

string doBackground(string $function, string $workload, string|null $unique = null)

Runs a task in the background, returning a job handle which can be used to get the status of the running task.

Parameters

string $function
string $workload
string|null $unique

Return Value

string

The job handle for the submitted task

string doHighBackground(string $function, string $workload, string|null $unique = null)

Runs a high priority task in the background, returning a job handle which can be used to get the status of the running task. High priority tasks take precedence over normal and low priority tasks in the job queue.

Parameters

string $function
string $workload
string|null $unique

Return Value

string

The job handle for the submitted task

string doLowBackground(string $function, string $workload, string|null $unique = null)

Runs a low priority task in the background, returning a job handle which can be used to get the status of the running task. Normal and high priority tasks take precedence over low priority tasks in the job queue.

Parameters

string $function
string $workload
string|null $unique

Return Value

string

The job handle for the submitted task

array jobStatus(string $job_handle)

Object oriented style (method):.

Parameters

string $job_handle

Return Value

array

An array containing status information for the job corresponding to the supplied job handle. The first array element is a boolean indicating whether the job is even known, the second is a boolean indicating whether the job is still running, and the third and fourth elements correspond to the numerator and denominator of the fractional completion percentage, respectively

GearmanTask|false addTask(string $function_name, string $workload, mixed $context = null, string|null $unique = null)

Adds a task to be run in parallel with other tasks. Call this method for all the tasks to be run in parallel, then call GearmanClient::runTasks to perform the work. Note that enough workers need to be available for the tasks to all run in parallel.

Parameters

string $function_name
string $workload
mixed $context
string|null $unique

Return Value

GearmanTask|false

A GearmanTask object or false if the task could not be added

GearmanTask|false addTaskHigh(string $function_name, string $workload, mixed $context = null, string|null $unique = null)

Adds a high priority task to be run in parallel with other tasks. Call this method for all the high priority tasks to be run in parallel, then call GearmanClient::runTasks to perform the work. Tasks with a high priority will be selected from the queue before those of normal or low priority.

Parameters

string $function_name
string $workload
mixed $context
string|null $unique

Return Value

GearmanTask|false

A GearmanTask object or false if the task could not be added

GearmanTask|false addTaskLow(string $function_name, string $workload, mixed $context = null, string|null $unique = null)

Adds a low priority background task to be run in parallel with other tasks. Call this method for all the tasks to be run in parallel, then call GearmanClient::runTasks to perform the work. Tasks with a low priority will be selected from the queue after those of normal or low priority.

Parameters

string $function_name
string $workload
mixed $context
string|null $unique

Return Value

GearmanTask|false

A GearmanTask object or false if the task could not be added

GearmanTask|false addTaskBackground(string $function_name, string $workload, mixed $context = null, string|null $unique = null)

Adds a background task to be run in parallel with other tasks. Call this method for all the tasks to be run in parallel, then call GearmanClient::runTasks to perform the work.

Parameters

string $function_name
string $workload
mixed $context
string|null $unique

Return Value

GearmanTask|false

A GearmanTask object or false if the task could not be added

GearmanTask|false addTaskHighBackground(string $function_name, string $workload, mixed $context = null, string|null $unique = null)

Adds a high priority background task to be run in parallel with other tasks.

Call this method for all the tasks to be run in parallel, then call GearmanClient::runTasks to perform the work. Tasks with a high priority will be selected from the queue before those of normal or low priority.

Parameters

string $function_name
string $workload
mixed $context
string|null $unique

Return Value

GearmanTask|false

A GearmanTask object or false if the task could not be added

GearmanTask|false addTaskLowBackground(string $function_name, string $workload, mixed $context = null, string|null $unique = null)

Adds a low priority background task to be run in parallel with other tasks. Call this method for all the tasks to be run in parallel, then call GearmanClient::runTasks to perform the work. Tasks with a low priority will be selected from the queue after those of normal or high priority.

Parameters

string $function_name
string $workload
mixed $context
string|null $unique

Return Value

GearmanTask|false

A GearmanTask object or false if the task could not be added

GearmanTask addTaskStatus(string $job_handle, string $context = null)

Used to request status information from the Gearman server, which will call the specified status callback (set using GearmanClient::setStatusCallback).

Parameters

string $job_handle

The job handle for the task to get status for

string $context

Data to be passed to the status callback, generally a reference to an array or object

Return Value

GearmanTask

A GearmanTask object

bool setWorkloadCallback(callable $callback)

Sets a function to be called when a worker needs to send back data prior to job completion. A worker can do this when it needs to send updates, send partial results, or flush data during long running jobs. The callback should accept a single argument, a GearmanTask object.

Parameters

callable $callback

A function to call

Return Value

bool

bool setCreatedCallback(string $callback)

Sets a function to be called when a task is received and queued by the Gearman job server. The callback should accept a single argument, a GearmanClient oject.

Parameters

string $callback

A function to call

Return Value

bool

bool setDataCallback(callable $callback)

Sets the callback function for accepting data packets for a task. The callback function should take a single argument, a GearmanTask object.

Parameters

callable $callback

A function or method to call

Return Value

bool

bool setWarningCallback(callable $callback)

Sets a function to be called when a worker sends a warning. The callback should accept a single argument, a GearmanTask object.

Parameters

callable $callback

A function to call

Return Value

bool

bool setStatusCallback(callable $callback)

Sets a callback function used for getting updated status information from a worker. The function should accept a single argument, a GearmanTask object.

Parameters

callable $callback

A function to call

Return Value

bool

bool setCompleteCallback(callable $callback)

Use to set a function to be called when a task is completed. The callback function should accept a single argument, a GearmanTask oject.

Parameters

callable $callback

A function to be called

Return Value

bool

bool setExceptionCallback(callable $callback)

Specifies a function to call when a worker for a task sends an exception.

Parameters

callable $callback

Function to call when the worker throws an exception

Return Value

bool

bool setFailCallback(callable $callback)

Sets the callback function to be used when a task does not complete successfully. The function should accept a single argument, a GearmanTask object.

Parameters

callable $callback

A function to call

Return Value

bool

bool clearCallbacks()

Clears all the task callback functions that have previously been set.

Return Value

bool

Always returns true

bool runTasks()

For a set of tasks previously added with GearmanClient::addTask, GearmanClient::addTaskHigh, GearmanClient::addTaskLow, GearmanClient::addTaskBackground, GearmanClient::addTaskHighBackground, or GearmanClient::addTaskLowBackground, this call starts running the tasks in parallel.

Return Value

bool

bool ping(string $workload)

Sends some arbitrary data to all job servers to see if they echo it back.

The data sent is not used or processed in any other way. Primarily used for testing and debugging.

Parameters

string $workload

Return Value

bool