狐狸情 发表于 2018-12-20 07:36:50

php使用zeromq

  Zeromq是个啥玩意?

  Connect your code in any language, on any platform.
Carries messages across inproc, IPC, TCP, TPIC, multicast.
Smart patterns like pub-sub, push-pull, and router-dealer.
High-speed asynchronous I/O engines, in a tiny library.
Backed by a large and active open source community.
Supports every modern language and platform.
Build any architecture: centralized, distributed, small, or large.
Free software with full commercial support
  

  以上是官方页面的介绍,大意是说一种跨平台,可以使用任何语言使用的消息中间件,可以通过inproc,IPC,TCP,TPIC,多播的消息传递消息,包括多种模式,pub-sub(分发-订阅),push-pull(推送模式),router-dealer(路由模式)等等等等。极高的处理速度是其重要的特性之一。
  官方详细介绍请访问:http://zeromq.org/
  

  安装:
  #wget http://download.zeromq.org/zeromq-4.0.4.tar.gz
  #tar zxvf zeromq-4.0.4.tar.gz
  #cd zeromq-4.0.4
  #./configure=/usr/local/zeromq404
  #make
  #make install
  

  安装PHP扩展:

  #git clone git://github.com/mkoppanen/php-zmq.git

  #cd php-zmq
  #/usr/local/php/bin/phpize         //自己PHP的安装目录,根据需要更改
  #./configure --with-php-config=/usr/local/php/bin/php-config --with-zmq=/usr/local/zeromq404    //php-config需要根据自己的情况进行更改
  #make
  #make install
  

  安装好之后会在/usr/local/php/lib/php/extensions/no-debug-zts-20090626/目录下面生成zmq.so
  

  修改配置文件:
  #vim /etc/php.ini
  修改extension_dir="/usr/local/php/lib/php/extensions/no-debug-zts-20090626/"
  增加extension=zmq.so
  

  重启apache
  访问phpinfo,如果看到zmq的相关信息表明已经OK了
  

  测试:
  系统分两部分:client和server端
  server端一般由phpcli来执行,常驻后台,监听一个端口,此例中使用5555,代码如下:
  

  zmqserver.php
  
页: [1]
查看完整版本: php使用zeromq