Connection.phpView Source

Show: PublicProtectedPrivateinherited
Table of Contents
Interface for Danga's Gearman job scheduling system

PHP version 5.1.0+

LICENSE: This source file is subject to the New BSD license that is available through the world-wide-web at the following URI: http://www.opensource.org/licenses/bsd-license.php. If you did not receive a copy of the New BSD License and are unable to obtain it through the web, please send a note to license@php.net so we can mail you a copy immediately.

Author
Joe Stump  
Category
Net  
Copyright
2007-2008 Digg.com, Inc.  
License
New BSD License  
Link
http://pear.php.net/package/Net_Gearman  
Link
http://www.danga.com/gearman/  
Package
ShSo\Net\Gearman  
Version
CVS: $Id$  

\ShSo\Net\Gearman\Connection

Package: ShSo\Net\Gearman
The base connection class
Author
Joe Stump  
Category
Net  
Copyright
2007-2008 Digg.com, Inc.  
License
New BSD License  
Link
http://www.danga.com/gearman/  
Version
Release: @package_version@  

Properties

>VPropertyprotectedarray $commands = array('can_do' => array(1, array('func')), 'can_do_timeout' => array(23, array('func', 'timeout')), 'cant_do' => array(2, array('func')), 'reset_abilities' => array(3, array()), 'set_client_id' => array(22, array('client_id')), 'pre_sleep' => array(4, array()), 'noop' => array(6, array()), 'submit_job' => array(7, array('func', 'uniq', 'arg')), 'submit_job_high' => array(21, array('func', 'uniq', 'arg')), 'submit_job_bg' => array(18, array('func', 'uniq', 'arg')), 'submit_job_high_bg' => array(32, array('func', 'uniq', 'arg')), 'submit_job_low' => array(33, array('func', 'uniq', 'arg')), 'submit_job_low_bg' => array(34, array('func', 'uniq', 'arg')), 'job_created' => array(8, array('handle')), 'grab_job' => array(9, array()), 'no_job' => array(10, array()), 'job_assign' => array(11, array('handle', 'func', 'arg')), 'work_status' => array(12, array('handle', 'numerator', 'denominator')), 'work_complete' => array(13, array('handle', 'result')), 'work_fail' => array(14, array('handle')), 'get_status' => array(15, array('handle')), 'status_res' => array(20, array('handle', 'known', 'running', 'numerator', 'denominator')), 'echo_req' => array(16, array('text')), 'echo_res' => array(17, array('text')), 'error' => array(19, array('err_code', 'err_text')), 'all_yours' => array(24, array()))
static
A list of valid Gearman commands

This is a list of valid Gearman commands (the key of the array), their integery type (first key in second array) used in the binary header, and the arguments / order of arguments to send/receive.

Default valuearray('can_do' => array(1, array('func')), 'can_do_timeout' => array(23, array('func', 'timeout')), 'cant_do' => array(2, array('func')), 'reset_abilities' => array(3, array()), 'set_client_id' => array(22, array('client_id')), 'pre_sleep' => array(4, array()), 'noop' => array(6, array()), 'submit_job' => array(7, array('func', 'uniq', 'arg')), 'submit_job_high' => array(21, array('func', 'uniq', 'arg')), 'submit_job_bg' => array(18, array('func', 'uniq', 'arg')), 'submit_job_high_bg' => array(32, array('func', 'uniq', 'arg')), 'submit_job_low' => array(33, array('func', 'uniq', 'arg')), 'submit_job_low_bg' => array(34, array('func', 'uniq', 'arg')), 'job_created' => array(8, array('handle')), 'grab_job' => array(9, array()), 'no_job' => array(10, array()), 'job_assign' => array(11, array('handle', 'func', 'arg')), 'work_status' => array(12, array('handle', 'numerator', 'denominator')), 'work_complete' => array(13, array('handle', 'result')), 'work_fail' => array(14, array('handle')), 'get_status' => array(15, array('handle')), 'status_res' => array(20, array('handle', 'known', 'running', 'numerator', 'denominator')), 'echo_req' => array(16, array('text')), 'echo_res' => array(17, array('text')), 'error' => array(19, array('err_code', 'err_text')), 'all_yours' => array(24, array()))Details
Type
array
See
 
See
 
>VPropertyprotectedarray $magic = array()
static
The reverse of ShSo\Net\Gearman\Connection::$commands

This is the same as the ShSo\Net\Gearman\Connection::$commands array only it's keyed by the magic (integer value) value of the command.

Default valuearray()Details
Type
array
See
 
See
 
>VPropertyprotectedinteger $multiByteSupport = null
static
Is PHP's multibyte overload turned on?
Default valuenullDetails
Type
integer
>VPropertypublicarray $waiting = array()
static
Tasks waiting for a handle

Tasks are popped onto this queue as they're submitted so that they can later be popped off of the queue once a handle has been assigned via the job_created command.

Default valuearray()Details
Type
array
Access
public  
Static
 

Methods

methodprivate__construct() : void
final

Constructor

methodpublicblockingRead(resource $socket, float $timeout = 500) : array
static

Blocking socket read

Parameters
NameTypeDescription
$socketresource

The socket to read from

$timeoutfloat

The timeout for the read

Returns
TypeDescription
array
Throws
ExceptionDescription
\ShSo\Net\Gearman\ShSo\Net\Gearman\Exceptionon timeouts
methodpublicclose(resource $socket) : void
static

Close the connection

Parameters
NameTypeDescription
$socketresource

The connection/socket to close

methodpublicconnect(string $host = 'localhost', integer $timeout = 2000) : resource
static

Connect to Gearman

Opens the socket to the Gearman Job server. It throws an exception if a socket error occurs. Also populates ShSo\Net\Gearman\Connection::$magic.

Parameters
NameTypeDescription
$hoststring

e.g. 127.0.0.1 or 127.0.0.1:7003

$timeoutinteger

Timeout in milliseconds

Returns
TypeDescription
resourceA connection to a Gearman server
Throws
ExceptionDescription
\ShSo\Net\Gearman\ShSo\Net\Gearman\Exceptionwhen it can't connect to server
Details
See
 
See
 
See
 
methodpublicisConnected(resource $conn) : boolean
static

Are we connected?

Parameters
NameTypeDescription
$connresource

The connection/socket to check

Returns
TypeDescription
booleanFalse if we aren't connected
methodpublicread(resource $socket) : array
static

Read command from Gearman

Parameters
NameTypeDescription
$socketresource

The socket to read from

Returns
TypeDescription
arrayResult read back from Gearman
Throws
ExceptionDescription
\ShSo\Net\Gearman\ShSo\Net\Gearman\Exceptionconnection issues or invalid responses
Details
See
 
methodpublicsend(resource $socket, string $command, array $params = array()) : boolean
static

Send a command to Gearman

This is the command that takes the string version of the command you wish to run (e.g. 'can_do', 'grab_job', etc.) along with an array of parameters (in key value pairings) and packs it all up to send across the socket.

Parameters
NameTypeDescription
$socketresource

The socket to send the command to

$commandstring

Command to send (e.g. 'can_do')

$paramsarray

Params to send

Returns
TypeDescription
boolean
Throws
ExceptionDescription
\ShSo\Net\Gearman\ShSo\Net\Gearman\Exceptionon invalid command or unable to write
Details
See
ShSo\Net\Gearman\Connection::$socket  
methodpublicstringLength(string $value) : integer
static

Determine if we should use mb_strlen or stock strlen

Parameters
NameTypeDescription
$valuestring

The string value to check

Returns
TypeDescription
integerSize of string
Details
See
 
methodpublicsubString(string $str, integer $start, integer $length) : string
static

Multibyte substr() implementation

Parameters
NameTypeDescription
$strstring

The string to substr()

$startinteger

The first position used

$lengthinteger

The maximum length of the returned string

Returns
TypeDescription
stringPortion of $str specified by $start and $length
Details
Link
http://us3.php.net/mb_substr  
Link
http://us3.php.net/substr  
See
 
Documentation was generated by phpDocumentor 2.8.5.