class ZMQDevice (View source)

Class ZMQDevice

Methods

__construct(ZMQSocket $frontend, ZMQSocket $backend, ZMQSocket $listener = null)

(PECL zmq >= 1.0.4) Construct a new device.

int
getIdleTimeout()

Gets the idle callback timeout value.

int
getTimerTimeout()

Gets the timer callback timeout value.

run()

Runs the device.

setIdleCallback(callable $cb_func, int $timeout, mixed $user_data)

Sets the idle callback function.

setIdleTimeout(int $timeout)

Sets the idle callback timeout value. The idle callback is invoked periodically when the device is idle.

setTimerCallback(callable $cb_func, int $timeout, mixed $user_data)

Sets the timer callback function. The timer callback will be invoked after timeout has passed.

setTimerTimeout(int $timeout)

Sets the timer callback timeout value. The timer callback is invoked periodically if it's set.

Details

__construct(ZMQSocket $frontend, ZMQSocket $backend, ZMQSocket $listener = null)

(PECL zmq >= 1.0.4) Construct a new device.

"ØMQ devices can do intermediation of addresses, services, queues, or any other abstraction you care to define above the message and socket layers." -- zguide Call to this method will prepare the device. Usually devices are very long running processes so running this method from interactive script is not recommended. This method throw ZMQDeviceException if the device cannot be started.

Parameters

ZMQSocket $frontend

Frontend parameter for the devices. Usually where there messages are coming.

ZMQSocket $backend

Backend parameter for the devices. Usually where there messages going to.

ZMQSocket $listener

Listener socket, which receives a copy of all messages going both directions. The type of this socket should be SUB, PULL or DEALER.

int getIdleTimeout()

Gets the idle callback timeout value.

This method returns the idle callback timeout value. Added in ZMQ extension version 1.1.0.

Return Value

int

This method returns the idle callback timeout value.

int getTimerTimeout()

Gets the timer callback timeout value.

Added in ZMQ extension version 1.1.0.

Return Value

int

This method returns the timer timeout value.

run()

Runs the device.

Call to this method will block until the device is running. It is not recommended that devices are used from interactive scripts.

Exceptions

ZMQDeviceException

ZMQDevice setIdleCallback(callable $cb_func, int $timeout, mixed $user_data)

Sets the idle callback function.

If idle timeout is defined the idle callback function shall be called if the internal poll loop times out without events. If the callback function returns false or a value that evaluates to false the device is stopped. The callback function signature is callback (mixed $user_data).

Parameters

callable $cb_func

Callback function to invoke when the device is idle. Returning false or a value that evaluates to false from this function will cause the device to stop.

int $timeout

How often to invoke the idle callback in milliseconds. The idle callback is invoked periodically when there is no activity on the device. The timeout value guarantees that there is at least this amount of milliseconds between invocations of the callback function.

mixed $user_data

Additional data to pass to the callback function.

Return Value

ZMQDevice

On success this method returns the current object.

ZMQDevice setIdleTimeout(int $timeout)

Sets the idle callback timeout value. The idle callback is invoked periodically when the device is idle.

On success this method returns the current object.

Parameters

int $timeout

The idle callback timeout value in milliseconds

Return Value

ZMQDevice

On success this method returns the current object.

ZMQDevice setTimerCallback(callable $cb_func, int $timeout, mixed $user_data)

Sets the timer callback function. The timer callback will be invoked after timeout has passed.

The difference between idle and timer callbacks are that idle callback is invoked only when the device is idle. The callback function signature is callback (mixed $user_data). Added in ZMQ extension version 1.1.0.

Parameters

callable $cb_func

Callback function to invoke when the device is idle. Returning false or a value that evaluates to false from this function will cause the device to stop.

int $timeout

How often to invoke the idle callback in milliseconds. The idle callback is invoked periodically when there is no activity on the device. The timeout value guarantees that there is at least this amount of milliseconds between invocations of the callback function.

mixed $user_data

Additional data to pass to the callback function.

Return Value

ZMQDevice

ZMQDevice setTimerTimeout(int $timeout)

Sets the timer callback timeout value. The timer callback is invoked periodically if it's set.

Added in ZMQ extension version 1.1.0.

Parameters

int $timeout

The timer callback timeout value.

Return Value

ZMQDevice