失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > PHP消息队列httpsqs安装与使用无错版

PHP消息队列httpsqs安装与使用无错版

时间:2018-07-30 21:39:24

相关推荐

PHP消息队列httpsqs安装与使用无错版

php教程|php手册

PHP,消息,队列,httpsqs,安装,使用,无错,项目,

php教程-php手册

qq空间登录器源码,vscode打开vs工程,ubuntu加压zip,tomcat找不到so,webform爬虫,php 地图坐标,seo推广用什么引流,网址大全网站模板,个人精美网页模板lzw

项目网址 :/p/httpsqs/ 使用文档 :/httpsqs/ 说明:由于需要安装的东西有些多,原文可能写的有些简略,所以适当补充了 1.安装libevent-2.0.12-stable.tar.gz wget /files/libeven

大鱼吃小鱼游戏源码,vscode是ide,电视ubuntu,tomcat信息输出,sqlite存储对象类型,超级插件系小说下载统,前端框架控件搭建教程学习,学生模仿爬虫爬楼视频,php 字符 个数,惠州seo项目投放,自适应视频网站源码,网页固定 代码, login 模板lzw

手机论坛排行 源码,卸载双系统ubuntu,爬虫翻页没数据,php瀑布,谷歌seo合同lzw

项目网址:/p/httpsqs/

使用文档:/httpsqs/

说明:由于需要安装的东西有些多,原文可能写的有些简略,所以适当补充了

1.安装libevent-2.0.12-stable.tar.gz

wget /files/libevent-2.0.12-stable.tar.gz

tar zxvf libevent-2.0.12-stable.tar.gz

cd libevent-2.0.12-stable/

./configure –prefix=/usr/local/libevent-2.0.12-stable/

make

make install

cd ../

2.安装tokyocabinet-1.4.47.tar.gz

wget /files/tokyocabinet-1.4.47.tar.gz

tar zxvf tokyocabinet-1.4.47.tar.gz

cd tokyocabinet-1.4.47/

./configure –prefix=/usr/local/tokyocabinet-1.4.47/

#注:在32位Linux操作系统上编译Tokyo cabinet,请使用./configure –enable-off64代替./configure,可

以使数据库文件突破2GB的限制。

#./configure –enable-off64 –prefix=/usr/local/tokyocabinet-1.4.47/

make

make install

cd ../

当执行第二步骤的会出错,是由于缺少bzip2-1.0.6.tar.gz

下面进行安装

/1.0.6/bzip2-1.0.6.tar.gz安装开始;

wget /1.0.6/bzip2-1.0.6.tar.gz

tar -xvzf bzip2-1.0.6.tar.gz

cd bzip2-1.0.6.

make

make install

在重复安装tokyocabinet-1.4.47.tar.gz还是失败,由于缺少zlib-1.2.5.tar.gz

下面进行安装

/zLibDll/zlib-1.2.5.tar.gz安装开始;

wget /zLibDll/zlib-1.2.5.tar.gz

tar -xvzf zlib-1.2.5.tar.gz

cd zlib-1.2.5.

./configure

make

sudo make instal

继续第2步骤 OK

3.安装httpsqs-1.7.tar.gz

wget /files/httpsqs-1.7.tar.gz

tar zxvf httpsqs-1.7.tar.gz

cd httpsqs-1.7/

make

make install

cd ../

4.测试

如果安装成功 执行httpsqs –h 会出现

————————————————————————————————

HTTP Simple Queue Service – httpsqs v1.7 (April 14, )

Author: Zhang Yan (), E-mail: net@

This is free software, and you are welcome to modify and redistribute it under the New BSD

License

-l interface to listen on, default is 0.0.0.0

-p TCP port number to listen on (default: 1218)

-xdatabase directory (example: /opt/httpsqs/data)

-t keep-alive timeout for an http request (default: 60)

-s the interval to sync updated contents to the disk (default: 5)

-c the maximum number of non-leaf nodes to be cached (default: 1024)

-mdatabase memory cache size in MB (default: 100)

-isave PID in (default: /tmp/httpsqs.pid)

-athe auth password to access httpsqs (example: mypass123)

-d run as a daemon

-h print this help and exit

5.设置

存储目录

#mkdir /usr/local/httpsqs_queue

mkdir /home/bf

vi /home/bf/httpsqs.sh

内容如下:

#! /bin/sh

ulimit -SHn 65535

启动方法

带密码

# /usr/bin/httpsqs -d -p 1218 -t 10 -c 10000 -m 512 -x /usr/local/httpsqs_queue -a pwd123

无密码

# /usr/bin/httpsqs -d -p 1218 -t 10 -c 10000 -m 512 -x /usr/local/httpsqs_queue

干掉的方法

# killall httpsqs

注意需要打开防火墙端口

vim /etc/sysconfig/iptables

添加下面一行,打开防火墙1218端口:

-A INPUT -m state –state NEW -m tcp -p tcp –dport 1218 -j ACCEPT

重启防火墙

#/etc/init.d/iptables restart

6.使用

写队列

http://192.168.2.103:1218/?name=your_queue_name&opt=put&data=TEXT&auth=pwd123

读队列

http://192.168.2.103:1218/?charset=utf-8&name=your_queue_name&opt=get&auth=pwd123

写队列无密码

http://192.168.2.103:1218/?name=your_queue_name&opt=put&data=TEXT

读队列无密码

http://192.168.2.103:1218/?charset=utf-8&name=your_queue_name&opt=get

写队列

http://192.168.2.103:1218/?name=your_queue_name&opt=put&data=TEXT&auth=pwd123

读队列

http://192.168.2.103:1218/?charset=utf-8&name=your_queue_name&opt=get&auth=pwd123

7.php扩展

参考:/p/php-httpsqs-client/

安装说明

# mkdir php_httpsqs_client # cd php_httpsqs_client # wget http://php-httpsqs-/files/php_httpsqs_client_0.2.1.tar.gz# tar vzxf php_httpsqs_client_0.2.1.tar.gz# /usr/local/php/bin/phpize

如果

运行/usr/local/webserver/php/bin/phpize时出现:Configuring for:PHP Api Version: 1225Zend Module Api No:0613Zend Extension Api No: 20519Cannot find autoconf. Please check your autoconf installation and the$PHP_AUTOCONF environment variable. Then, rerun this script.根据网上的解决办法是:yum install m4yum install autoconf

# ./configure --enable-httpsqs --with-php-config=/usr/local/php/bin/php-config # make && make install

#接着在php.ini中添加一行 extension=httpsqs.so;

函数说明

/** * 创建httpsqs连接 * @param string $host 服务器地址,可以为空,默认为127.0.0.1 * @param int $port 服务器端口,可以为空,默认为1218 * @return resource */ $hr = httpsqs_connect("127.0.0.1",1218);

/** * 写入队列数据 * @param resource $hr服务器连接句柄 * @param string $queue 队列名称 * @param string $data 写入数据 * @param string $charset 字符集,可以为空,默认为utf-8 * @return boolean */ $putRes = httpsqs_put($hr,"testQueue","This is a test Data","UTF-8");

/** * 获取队列最后一条数据 * @param resource $hr * @param string $queue * @param boolean $return_array 是否返回数组,可以为空,默认为false 返回数组格式:array(pos=>队列插入点, data=>数据值) * @param string $charset 可以为空 * @return mixed */ $content = httpsqs_get($hr,"testQueue",true,"UTF-8");

/** * 获取队列状态 * @param resource $hr * @param string $queue * @param boolean $return_json 是否返回状态的json格式,可以为空,默认为false * @return string */ $status = httpsqs_status($hr,"testQueue",true);

/** * 获取队列某个点数据 * @param resource $hr * @param string $queue * @param int$pos 要获取的某条数据的位置 * @param string $charset 可以为空 * @return string */ $posData = httpsqs_view($hr,"testQueue",10,"UTF-8");

/** * 队列重置 * @param resource $hr * @param string $queue * @return boolean */ $resetRes = httpsqs_reset($hr,"testQueue");

/** * 设置队列最大数据条数 * @param resource $hr * @param string $queue * @param int$maxqueue 队列最大数据条数 * @return boolean */ $maxqueueRes = httpsqs_maxqueue($hr,"testQueue",10000);

/** * 修改定时刷新内存缓冲区内容到磁盘的间隔时间 * @param resource $hr * @param string $queue * @param int$synctime 间隔时间 * @return boolean */ $synctimeRes = httpsqs_synctime($hr,"testQueue",10);

对象调用

// 参数与httpsqs_connect对应 $hr =newHttpSQS($host, $port); // 参数与httpsqs_get对应 $hr->get($queuename, $return_array, $charset); // 参数与httpsqs_put对应 $hr->put($queuename, $data, $charset); // 参数与httpsqs_status对应 $hr->status($queuename, $return_json); // 参数与httpsqs_view对应 $hr->view($queuename, $pos); // 参数与httpsqs_reset对应 $hr->reset($queuename); // 参数与httpsqs_maxqueue对应 $hr->maxqueue($queuename); // 参数与httpsqs_synctime对应 $hr->synctime($queuename);

示例

// 取数据Daemon $hr = httpsqs_connect($host, $port); while(1){$data = httpsqs_get($hr, $queuename, $charset);if($data ===false){ sleep(1);}else{ // do something...} } // 或者 $hr =newHttpSQS($host, $port); while(1){$data = $hr->get($queuename, $charset);if($data ===false){ sleep(1);}else{ // do something...} } // 写数据 $hr = httpsqs_connect($hort, $port); httpsqs_put($hr, $queuename, $data, $charset); // 或者 $hr =newHttpSQS($hort, $port); $hr->put($queuename, $data, $charset);

写入

<?php

$hr = httpsqs_connect(“127.0.0.1”, 1218);

$putRes = httpsqs_put($hr, “testQueue”, “Text”, “UTF-8”);

?>

读取

<?php

$hr = httpsqs_connect(“127.0.0.1”, 1218);

$content = httpsqs_get($hr, “testQueue”, true, “UTF-8”);

//print_r($content);

echo $content[‘data’];

?>

如果觉得《PHP消息队列httpsqs安装与使用无错版》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。