Properties

$host_

$host_ : string

Remote hostname

Type

string

$port_

$port_ : integer

Remote port

Type

integer

$debug_

$debug_ : boolean

Debugging on?

Type

boolean

$debugHandler_

$debugHandler_ : mixed

Debug handler

Type

mixed

$handle_

$handle_ : resource

Handle to PHP socket

Type

resource

$sendTimeout_

$sendTimeout_ : integer

Send timeout in milliseconds

Type

integer

$recvTimeout_

$recvTimeout_ : integer

Recv timeout in milliseconds

Type

integer

$sendTimeoutSet_

$sendTimeoutSet_ : boolean

Is send timeout set?

Type

boolean

$persist_

$persist_ : boolean

Persistent socket or plain?

Type

boolean

$servers_

$servers_ : 

Remote servers. Array of associative arrays with 'host' and 'port' keys

Type

$numRetries_

$numRetries_ : integer

How many times to retry each host in connect

Type

integer

$retryInterval_

$retryInterval_ : integer

Retry interval in seconds, how long to not try a host if it has been marked as down.

Type

integer

$maxConsecutiveFailures_

$maxConsecutiveFailures_ : integer

Max consecutive failures before marking a host down.

Type

integer

$randomize_

$randomize_ : boolean

Try hosts in order? or Randomized?

Type

boolean

$alwaysTryLast_

$alwaysTryLast_ : boolean

Always try last host, even if marked down?

Type

boolean

Methods

__construct()

__construct(array  $hosts = array('localhost'), mixed  $ports = array(9090), boolean  $persist = FALSE, mixed  $debugHandler = null) 

Socket pool constructor

Parameters

array $hosts

List of remote hostnames

mixed $ports

Array of remote ports, or a single common port

boolean $persist

Whether to use a persistent socket

mixed $debugHandler

Function for error logging

setSendTimeout()

setSendTimeout(integer  $timeout) 

Sets the send timeout.

Parameters

integer $timeout

setRecvTimeout()

setRecvTimeout(integer  $timeout) 

Sets the receive timeout.

Parameters

integer $timeout

setDebug()

setDebug(boolean  $debug) 

Sets debugging output on or off

Parameters

boolean $debug

getHost()

getHost() : string

Get the host that this socket is connected to

Returns

string —

host

getPort()

getPort() : integer

Get the remote port that this socket is connected to

Returns

integer —

port

isOpen()

isOpen() : boolean

Whether this transport is open.

Returns

boolean —

true if open

open()

open() 

Connects the socket by iterating through all the servers in the pool and trying to find one that works.

close()

close() 

Close the transport.

readAll()

readAll(  $len) : string

Guarantees that the full amount of data is read.

Parameters

$len

Throws

\TTransportException

if cannot read data

Returns

string —

The data, of exact length

read()

read(integer  $len) : string

Read some data into the array.

Parameters

integer $len

How much to read

Throws

\TTransportException

if cannot read any more data

Returns

string —

The data that has been read

write()

write(string  $buf) 

Writes the given data out.

Parameters

string $buf

The data to write

Throws

\TTransportException

if writing fails

flush()

flush() 

Flushes any pending data out of a buffer

Throws

\TTransportException

if a writing error occurs

addServer()

addServer(string  $host, integer  $port) 

Add a server to the pool

This function does not prevent you from adding a duplicate server entry.

Parameters

string $host

hostname or IP

integer $port

port

setNumRetries()

setNumRetries(integer  $numRetries) 

Sets how many time to keep retrying a host in the connect function.

Parameters

integer $numRetries

setRetryInterval()

setRetryInterval(  $retryInterval) 

Sets how long to wait until retrying a host if it was marked down

Parameters

$retryInterval

setMaxConsecutiveFailures()

setMaxConsecutiveFailures(  $maxConsecutiveFailures) 

Sets how many time to keep retrying a host before marking it as down.

Parameters

$maxConsecutiveFailures

setRandomize()

setRandomize(boolean  $randomize) 

Turns randomization in connect order on or off.

Parameters

boolean $randomize

setAlwaysTryLast()

setAlwaysTryLast(boolean  $alwaysTryLast) 

Whether to always try the last server.

Parameters

boolean $alwaysTryLast