__socket = $g_zmqcontext->getSocket(ZMQ::SOCKET_SUB); $this->__socket->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, ""); $this->__socket->connect($uri); } function recv($deviceUID = "", $timeoutMs = -1) { $start = microtime(true) * 1000; $end = $start + $timeoutMs; while (true) { while (true) { $this->__socket->setSockOpt(ZMQ::SOCKOPT_RCVTIMEO, $timeoutMs); try { $r = $this->__socket->recv(); } catch (ZMQSocketException $e) { return null; } if (!$this->__socket->getSockOpt(ZMQ::SOCKOPT_RCVMORE)) break; } $msg = json_decode($r, true); if ($deviceUID == "") { break; } else { if ($msg['device:uid'] == $deviceUID) { break; } } if ((microtime(true) * 1000) > $end && $timeoutMs > 0) return null; } return $msg; } }