Last active
January 10, 2020 03:18
-
-
Save toknT/3de2b6211b9695e4f3c1eaf6c81abb3f to your computer and use it in GitHub Desktop.
php bitcoind zeromq sub demo
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 | |
// 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