Skip to content

Instantly share code, notes, and snippets.

@toknT
Last active January 10, 2020 03:18
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 toknT/3de2b6211b9695e4f3c1eaf6c81abb3f to your computer and use it in GitHub Desktop.
Save toknT/3de2b6211b9695e4f3c1eaf6c81abb3f to your computer and use it in GitHub Desktop.
php bitcoind zeromq sub demo
<?php
// require zmq extension in ubuntu run `sudo apt install php-zmq` to install it
$context = new \ZMQContext();
$subscriber = new \ZMQSocket($context, \ZMQ::SOCKET_SUB);
$subscriber->connect("tcp://192.168.1.136:28332");
$subscriber->setSockOpt(\ZMQ::SOCKOPT_SUBSCRIBE, "hashblock");
$subscriber->setSockOpt(\ZMQ::SOCKOPT_SUBSCRIBE, "hashtx");
$subscriber->setSockOpt(\ZMQ::SOCKOPT_SUBSCRIBE, "rawblock");
$subscriber->setSockOpt(\ZMQ::SOCKOPT_SUBSCRIBE, "rawtx");
while (true) {
$multiRec = $subscriber->recvMulti();
print(date('Y-m-d H:i:s') . ' rec:' . PHP_EOL);
$topic = $multiRec[0];
$body = \bin2hex($multiRec[1]);
$sequence = \bin2hex($multiRec[2]);
print("sequence : " . $sequence . PHP_EOL);
print("topic : " . $topic . PHP_EOL);
print("body : " . PHP_EOL);
print($body);
print(PHP_EOL);
print("---------------");
print(PHP_EOL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment