Skip to content

Instantly share code, notes, and snippets.

@phillyqueso
Created January 11, 2012 21:57
Show Gist options
  • Save phillyqueso/1597008 to your computer and use it in GitHub Desktop.
Save phillyqueso/1597008 to your computer and use it in GitHub Desktop.
<?php
class liveNode {
private $host = '127.0.0.1';
private $port = '5566';
static private $queue;
private $timeout = 5000; // milliseconds
public function __construct() {
if (!isset(self::$queue)) {
try {
self::$queue = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_REQ, "live");
self::$queue->connect('tcp://'.$this->host.':'.$this->port);
$poll = new ZMQPoll();
$id = $poll->add(self::$queue, ZMQ::POLL_IN);
$readable = $writeable = array();
$events = $poll->poll($readable, $writeable, $this->timeout);
} catch(ZMQPollException $e) {
throw new expection("problem with liveNode zmq connection: ".$e->getMessage());
return false;
}
}
return true;
}
public function send($room, $emit, $data) {
self::$queue->send(json_encode(array("room" => $room, "emit" => $emit, "data" => $data)));
self::$queue->recv();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment