Created
November 9, 2012 05:05
-
-
Save scragg0x/4043814 to your computer and use it in GitHub Desktop.
ZMQ wrapper, lazy connect
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 | |
// Just a wrapper class for ZMQ PECL extension | |
class ZMQ_Socket { | |
private $_context; | |
private $_socket; | |
private $_connected = false; | |
function __construct($opts = null) { | |
} | |
function connect() { | |
if ($this->_connected) { | |
return; | |
} | |
if (!$this->_context) { | |
$this->_context = new ZMQContext(); | |
} | |
$this->_socket = new ZMQSocket($this->_context, ZMQ::SOCKET_PUSH); | |
$this->_socket->connect("tcp://*:5555"); | |
$this->_connected = true; | |
} | |
function send($data) { | |
$this->connect(); | |
if (is_array($data)) { | |
$data = json_encode($data); | |
} | |
$this->_socket->send($data); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment