Tamil
Tamil

Reputation: 5358

Shared ZMQ Socket PHP

How to create a shared ZMQ socket using PHP? The scenario is

  1. User1 logs in to the system - A ZMQ bind happens and the user stays in the system
  2. User2 logs in to the system - Bind exception arises because of socket address already in use

How should we handle this issue using ZMQ?

Upvotes: 1

Views: 1283

Answers (2)

Tamil
Tamil

Reputation: 5358

The answer to this question is this post in SO

Method: ZMQContext::getSocket ( integer $type [, string $persistent_id = null [, callback $on_new_socket = null ]] )

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

Upvotes: 2

gneeek
gneeek

Reputation: 21

I think you want to use bind() for one process, and connect() for the other.

From the ZMQ Guide http://zguide.zeromq.org/page:all:

To create a connection between two nodes you use zmq_bind(3) in one node, and zmq_connect(3) in the other. As a general rule of thumb, the node which does zmq_bind(3) is a "server", sitting on a well-known network address, and the node which does zmq_connect(3) is a "client", with unknown or arbitrary network addresses. Thus we say that we "bind a socket to an endpoint" and "connect a socket to an endpoint", the endpoint being that well-known network address.

Upvotes: 2

Related Questions