Skip to content

Instantly share code, notes, and snippets.

@felixfyi
Forked from chobie/gist:589911
Created June 26, 2012 14:55
Show Gist options
  • Save felixfyi/2996254 to your computer and use it in GitHub Desktop.
Save felixfyi/2996254 to your computer and use it in GitHub Desktop.

how to install ZeroMQ php binding?

see also http://www.zeromq.org/bindings:php

wget http://www.zeromq.org/local--files/area:download/zeromq-2.0.9.tar.gz
tar zxf zeromq-2.0.9.tar.gz
cd zeromq-2.0.9
./configure
make && make install
cd ..
git clone git://github.com/mkoppanen/php-zmq.git
cd php-zmq
phpize && ./configure
make && make install
echo 'extension=zmq.so' > /etc/php.d/zeromq.ini

server.php

<?php
$server = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_PUB);
$server->bind("tcp://127.0.0.1:5555");

for(;;){
	echo "say Hello to subscriber." . PHP_EOL;
	$server->send("test Hello");
  sleep(1);
}
?>

client.php

<?php
$queue = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_SUB);
$queue->connect("tcp://127.0.0.1:5555");
// testに前方一致したメッセージを拾うよ
$queue->setsockopt(ZMQ::SOCKOPT_SUBSCRIBE,"test");

var_dump($queue->recv());
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment