Connection.php
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
- 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

array $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()))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.
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()))Details
integer $multiByteSupport = nullnullDetails- Type
- integer
Methods

blockingRead(resource $socket, float $timeout = 500) : arrayBlocking socket read
| Name | Type | Description |
|---|---|---|
| $socket | resource | The socket to read from |
| $timeout | float | The timeout for the read |
| Type | Description |
|---|---|
| array |
| Exception | Description |
|---|---|
| \ShSo\Net\Gearman\ShSo\Net\Gearman\Exception | on timeouts |

close(resource $socket) : voidClose the connection
| Name | Type | Description |
|---|---|---|
| $socket | resource | The connection/socket to close |

connect(string $host = 'localhost', integer $timeout = 2000) : resourceConnect 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.
| Name | Type | Description |
|---|---|---|
| $host | string | e.g. 127.0.0.1 or 127.0.0.1:7003 |
| $timeout | integer | Timeout in milliseconds |
| Type | Description |
|---|---|
| resource | A connection to a Gearman server |
| Exception | Description |
|---|---|
| \ShSo\Net\Gearman\ShSo\Net\Gearman\Exception | when it can't connect to server |

isConnected(resource $conn) : booleanAre we connected?
| Name | Type | Description |
|---|---|---|
| $conn | resource | The connection/socket to check |
| Type | Description |
|---|---|
| boolean | False if we aren't connected |

send(resource $socket, string $command, array $params = array()) : booleanSend 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.
| Name | Type | Description |
|---|---|---|
| $socket | resource | The socket to send the command to |
| $command | string | Command to send (e.g. 'can_do') |
| $params | array | Params to send |
| Type | Description |
|---|---|
| boolean |
| Exception | Description |
|---|---|
| \ShSo\Net\Gearman\ShSo\Net\Gearman\Exception | on invalid command or unable to write |

subString(string $str, integer $start, integer $length) : stringMultibyte substr() implementation
| Name | Type | Description |
|---|---|---|
| $str | string | The string to substr() |
| $start | integer | The first position used |
| $length | integer | The maximum length of the returned string |
| Type | Description |
|---|---|
| string | Portion of $str specified by $start and $length |