-
Notifications
You must be signed in to change notification settings - Fork 119
Persistent context socket
ZMQContext can be initialized using “is_persistent” boolean parameter. If set to true (default: true) the context will be persisted over requests.
ZMQSocket can be constructed using a parameter ‘persistent_id’. This value is used as a key for persisting socket and retrieving over multiple requests. The persistent socket must be allocated using a persistent context and will fall back being non-persistent if the context is non-persistent.
Sockets are stored using persistent list key ‘zeromq_socket:[%d]-[%s]’ where %d is the socket type and %s is the persistent_id. Therefore the following code:
$s1 = new ZeroMQ(ZeroMQ::SOCKET_P2P, 'myappsocket');
$s2 = new ZeroMQ(ZeroMQ::SOCKET_REP, 'myappsocket');
would create two separate sockets. Only sockets with same type and persistent id are shared between different objects.
Note: It’s important to remember that careless use of persistent sockets can exhaust available file-handles on the machine.