/** * 构造函数 * * @params $context ZMQContext * @params $endpoints 套接字链接到的端点 */ public function __construct($context, $endpoints) { if (APS::get_instance()->get_zmq_enabled()) { $socket = new ZMQSocket($context, ZMQ::SOCKET_XREQ); $socket->setsockopt(ZMQ::SOCKOPT_LINGER, 0); $socket->setsockopt(ZMQ::SOCKOPT_HWM, 1000); foreach ($endpoints as $endpoint) { $socket->connect($endpoint); } self::$sockets[] = $socket; $this->socket = $socket; } }
public function __construct($spID = null, $spVer = null, $sender = null, $linger = 100, $sndhwm = 1000, $rcvhwm = 1000) { if (self::$context === null) { self::$context = new ZMQContext(1, false); self::$poller = new ZMQPoll(); } $socket = new ZMQSocket(self::$context, ZMQ::SOCKET_DEALER); $socket->setsockopt(ZMQ::SOCKOPT_LINGER, $linger); $socket->setsockopt(ZMQ::SOCKOPT_SNDHWM, $sndhwm); $socket->setsockopt(ZMQ::SOCKOPT_RCVHWM, $rcvhwm); self::$poller->add($socket, ZMQ::POLL_IN); $this->socket = $socket; $this->spID = $spID; $this->spVer = $spVer; $this->sender = $sender; }
/** * Creates an APS client and returns the handler. * * @param $spID string * @param $spVer string * @param $sender string * @return The APS client handler on success or false on failure. */ function aps_new($spID = null, $spVer = null, $sender = null) { if (APSContext::$context === null) { APSContext::$context = new ZMQContext(3, false); } $socket = new ZMQSocket(APSContext::$context, ZMQ::SOCKET_DEALER); $socket->setsockopt(ZMQ::SOCKOPT_LINGER, APSContext::$linger); /* $socket->setsockopt(ZMQ::SOCKOPT_SNDHWM, APSContext::$sndhwm); $socket->setsockopt(ZMQ::SOCKOPT_RCVHWM, APSContext::$rcvhwm); */ if (APSContext::$poller === null) { APSContext::$poller = new ZMQPoll(); } APSContext::$poller->add($socket, ZMQ::POLL_IN); //Add item to the poll set $aps = new StdClass(); $aps->socket = $socket; $aps->spID = $spID; $aps->spVer = $spVer; $aps->sender = $sender; return $aps; }