Created
January 11, 2012 21:57
-
-
Save phillyqueso/1597008 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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