class ZMQContext (View source)

Class ZMQContext

Methods

__construct(int $io_threads = 1, bool $is_persistent = true)

Constructs a new ZMQ context. The context is used to initialize sockets.

string|int
getOpt(string $key)

(PECL zmq >= 1.0.4) Returns the value of a context option.

getSocket(int $type, string $persistent_id = null, callable $on_new_socket = null)

(PECL zmq >= 0.5.0) Shortcut for creating new sockets from the context.

bool
isPersistent()

(PECL zmq >= 0.5.0) Whether the context is persistent.

setOpt(int $key, mixed $value)

(PECL zmq >= 1.0.4) Sets a ZMQ context option. The type of the value depends on the key.

Details

__construct(int $io_threads = 1, bool $is_persistent = true)

Constructs a new ZMQ context. The context is used to initialize sockets.

A persistent context is required to initialize persistent sockets.

Parameters

int $io_threads

Number of io-threads in the context

bool $is_persistent

Whether the context is persistent. Persistent context is stored over multiple requests and is a requirement for persistent sockets.

string|int getOpt(string $key)

(PECL zmq >= 1.0.4) Returns the value of a context option.

Parameters

string $key

An int representing the option. See the ZMQ::CTXOPT_* constants.

Return Value

string|int

Returns either a string or an integer depending on key. Throws ZMQContextException on error.

Exceptions

ZMQContextException

ZMQSocket getSocket(int $type, string $persistent_id = null, callable $on_new_socket = null)

(PECL zmq >= 0.5.0) Shortcut for creating new sockets from the context.

If the context is not persistent the persistent_id parameter is ignored and the socket falls back to being non-persistent. The on_new_socket is called only when a new underlying socket structure is created.

Parameters

int $type

ZMQ::SOCKET_* constant to specify socket type.

string $persistent_id

If persistent_id is specified the socket will be persisted over multiple requests.

callable $on_new_socket

Callback function, which is executed when a new socket structure is created. This function does not get invoked if the underlying persistent connection is re-used. The callback takes ZMQSocket and persistent_id as two arguments.

Return Value

ZMQSocket

Exceptions

ZMQSocketException

bool isPersistent()

(PECL zmq >= 0.5.0) Whether the context is persistent.

Persistent context is needed for persistent connections as each socket is allocated from a context.

Return Value

bool

Returns TRUE if the context is persistent and FALSE if the context is non-persistent.

ZMQContext setOpt(int $key, mixed $value)

(PECL zmq >= 1.0.4) Sets a ZMQ context option. The type of the value depends on the key.

See ZMQ Constant Types for more information.

Parameters

int $key

One of the ZMQ::CTXOPT_* constants.

mixed $value

The value of the parameter.

Return Value

ZMQContext

Exceptions

ZMQContextException