windows下php使用zerophp
官网地址:http://zeromq.org/
下载windows版本安装(不过php可以不用安装,直接使用扩展包就可以了)
然后下载php的zmq扩展包:https://pecl.php.net/package/zmq/1.1.2/windows https://windows.php.net/downloads/pecl/releases/zmq/1.1.2/
打开压缩包有两个dll文件,一个readme:
readme里面是一个demo代码。
libzmq.dll需要放到C:\Windows\SysWOW64 C:\Windows\System32 目录下,不然会提示:未安装libzmq
参考文件:https://jingyan.baidu.com/article/7e44095335e2172fc1e2ef74.html
然后安装php的扩展zmq:
然后php使用zeromq:
send.php
$context = new ZMQContext();
// Socket to talk to server
echo "Connecting to hello world server".PHP_EOL;
$requester = new ZMQSocket($context, ZMQ::SOCKET_REQ);
$requester->connect("tcp://localhost:5555");
$date = time();
if($requester->send($date) !== false){
echo "send success\n";
}
$reply = $requester->recv();
printf ("Received:[%s]\n",$reply);
get.php
$context = new ZMQContext(1);
// Socket to talk to clients
$responder = new ZMQSocket($context, ZMQ::SOCKET_REP);
$responder->bind("tcp://*:5555");
while (true) {
$request = $responder->recv();
printf ("Received request: [%s]\n", $request);
usleep (100);
$responder->send("World");
}
执行:开启消费者长进程,php get.php 持续等待消息
然后执行生产者 php send.php
这样生产者插入一条 消费者即可看到一条