Skip to content

Instantly share code, notes, and snippets.

@scragg0x
Created November 9, 2012 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scragg0x/4043814 to your computer and use it in GitHub Desktop.
Save scragg0x/4043814 to your computer and use it in GitHub Desktop.
ZMQ wrapper, lazy connect
<?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