GearmanClient
class GearmanClient (View source)
Class: GearmanClient
Methods
Creates a GearmanClient instance representing a client that connects to the job server and submits tasks to complete.
Returns the last Gearman return code.
Returns an error string for the last error encountered.
Value of errno in the case of a GEARMAN_ERRNO return value.
No description
Sets one or more client options.
Adds one or more options to those already set.
Removes (unsets) one or more options.
Returns the timeout in milliseconds to wait for I/O activity.
Sets the timeout for socket I/O activity.
Get the application context previously set with GearmanClient::setContext.
Sets an arbitrary string to provide application context that can later be retrieved by GearmanClient::context.
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.
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.
No description
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.
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.
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.
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.
Returns the status for the running task. This should be used between repeated GearmanClient::do calls.
Runs a task in the background, returning a job handle which can be used to get the status of the running task.
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.
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.
Object oriented style (method):.
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.
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.
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.
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.
Adds a high priority background task to be run in parallel with other tasks.
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.
Used to request status information from the Gearman server, which will call the specified status callback (set using GearmanClient::setStatusCallback).
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.
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.
Sets the callback function for accepting data packets for a task. The callback function should take a single argument, a GearmanTask object.
Sets a function to be called when a worker sends a warning. The callback should accept a single argument, a GearmanTask object.
Sets a callback function used for getting updated status information from a worker. The function should accept a single argument, a GearmanTask object.
Use to set a function to be called when a task is completed. The callback function should accept a single argument, a GearmanTask oject.
Specifies a function to call when a worker for a task sends an exception.
Sets the callback function to be used when a task does not complete successfully. The function should accept a single argument, a GearmanTask object.
Clears all the task callback functions that have previously been set.
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.
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.
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.
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.
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.
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).
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.
The data sent is not used or processed in any other way. Primarily used for testing and debugging.