Skip to content

Instantly share code, notes, and snippets.

@jgupta
Created August 9, 2012 21:48
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 jgupta/3308327 to your computer and use it in GitHub Desktop.
Save jgupta/3308327 to your computer and use it in GitHub Desktop.
sub.php
<?php
$context = new ZMQContext();
// Socket to talk to server
$subscriber = new ZMQSocket($context, ZMQ::SOCKET_SUB);
$subscriber->connect("tcp://127.0.0.1:5555");
$subscriber->setSockOpt(ZMQ::SOCKOPT_SUBSCRIBE, 'hello');
$subscriber->setSockOpt(ZMQ::SOCKOPT_HWM, 10);
$count = 0;
$last = 0;
$start = round(microtime(true),2);
$i=0;
echo 'memory: '.memory_get_usage() . "\n";
while (true) {
if ($subscriber->recv()) {
$count++;
}
if (round(microtime(true),2)==$start+1) {
echo $count-$last."\n";
$last=$count;
$start=round(microtime(true),2);
echo 'memory: '.memory_get_usage() . "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment