ZMQ WITH PHP
时间:2011-03-21 来源:Enoch
zeromq 又称 OMQ 是个快速的消息服务 ,用这个可以很容易的实现PHP的 worker 不需要gearman
http://php.zero.mq/ http://weblet.jp/2010/10/phpzeromq%E3%80%80php-zmq%E3%82%92centos%E3%81%AB%E5%85%A5%E3%82%8C%E3%81%A6%E3%81%BF%E3%81%9F/ wget http://download.zeromq.org/zeromq-2.1.2.tar.gz tar zxvf ./configure --prefix=/usr/local/zeromq X 指定路径后 安装php-zmq找不到了 不知道如何指定 make && make install git clone git://github.com/mkoppanen/php-zmq.git phpize ./configure --with-php-config=/home/service/php/bin/php-config
checking for pkg-config... /usr/bin/pkg-config
checking libzmq installation... configure: error: Unable to find libzmq installation 出现这个错误 不知道如何指定zmq的安装路径 重新安装了zmq 改为默认安装 make && make install SERVER IN PHP http://zguide.zeromq.org/php:chapter2 $receiver = new ZMQSocket($context, ZMQ::SOCKET_PULL);
$receiver->bind("tcp://*:5558");
// Socket for worker control
///$controller = new ZMQSocket($context, ZMQ::SOCKET_PUB);
//$controller->bind("tcp://*:5559");
// Wait for start of batch
$string = $receiver->recv();
// Process 100 confirmations
$tstart = microtime(true);
$total_msec = 0; // Total calculated cost in msecs
for ($task_nbr = 0; $task_nbr < 100; $task_nbr++) {
$string = $receiver->recv();
var_dump($string);
}
$tend = microtime(true);
$total_msec = ($tend - $tstart) * 1000;
echo PHP_EOL;
printf ("Total elapsed time: %d msec", $total_msec);
echo PHP_EOL; Client IN php $context = new ZMQContext();
// Connect to task ventilator
$sender = new ZMQSocket($context, ZMQ::SOCKET_PUSH);
$sender->connect("tcp://localhost:5558");
$sender->send('123');
http://php.zero.mq/ http://weblet.jp/2010/10/phpzeromq%E3%80%80php-zmq%E3%82%92centos%E3%81%AB%E5%85%A5%E3%82%8C%E3%81%A6%E3%81%BF%E3%81%9F/ wget http://download.zeromq.org/zeromq-2.1.2.tar.gz tar zxvf ./configure --prefix=/usr/local/zeromq X 指定路径后 安装php-zmq找不到了 不知道如何指定 make && make install git clone git://github.com/mkoppanen/php-zmq.git phpize ./configure --with-php-config=/home/service/php/bin/php-config
checking for pkg-config... /usr/bin/pkg-config
checking libzmq installation... configure: error: Unable to find libzmq installation 出现这个错误 不知道如何指定zmq的安装路径 重新安装了zmq 改为默认安装 make && make install SERVER IN PHP http://zguide.zeromq.org/php:chapter2 $receiver = new ZMQSocket($context, ZMQ::SOCKET_PULL);
$receiver->bind("tcp://*:5558");
// Socket for worker control
///$controller = new ZMQSocket($context, ZMQ::SOCKET_PUB);
//$controller->bind("tcp://*:5559");
// Wait for start of batch
$string = $receiver->recv();
// Process 100 confirmations
$tstart = microtime(true);
$total_msec = 0; // Total calculated cost in msecs
for ($task_nbr = 0; $task_nbr < 100; $task_nbr++) {
$string = $receiver->recv();
var_dump($string);
}
$tend = microtime(true);
$total_msec = ($tend - $tstart) * 1000;
echo PHP_EOL;
printf ("Total elapsed time: %d msec", $total_msec);
echo PHP_EOL; Client IN php $context = new ZMQContext();
// Connect to task ventilator
$sender = new ZMQSocket($context, ZMQ::SOCKET_PUSH);
$sender->connect("tcp://localhost:5558");
$sender->send('123');
相关阅读 更多 +