当前位置: 首页 > 编程日记 > 正文

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

项目网址:http://code.google.com/p/httpsqs/
使用文档:http://blog.s135.com/httpsqs/

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

1.安装libevent-2.0.12-stable.tar.gz
wget http://httpsqs.googlecode.com/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 http://httpsqs.googlecode.com/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
下面进行安装

http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz安装开始; 
wget  http://www.bzip.org/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
下面进行安装

http://www.winimage.com/zLibDll/zlib-1.2.5.tar.gz安装开始; 
wget  http://www.winimage.com/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 http://httpsqs.googlecode.com/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, 2011) 
 
 
Author: Zhang Yan (http://blog.s135.com), E-mail: net@s135.com 
This is free software, and you are welcome to modify and redistribute it under the New BSD

License 
 
 
-l <ip_addr>  interface to listen on, default is 0.0.0.0 
-p <num>      TCP port number to listen on (default: 1218) 
-x <path>     database directory (example: /opt/httpsqs/data) 
-t <second>   keep-alive timeout for an http request (default: 60) 
-s <second>   the interval to sync updated contents to the disk (default: 5) 
-c <num>      the maximum number of non-leaf nodes to be cached (default: 1024) 
-m <size>     database memory cache size in MB (default: 100) 
-i <file>     save PID in <file> (default: /tmp/httpsqs.pid) 
-a <auth>     the 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扩展

参考:http://code.google.com/p/php-httpsqs-client/

安装说明

# mkdir php_httpsqs_client 
# cd php_httpsqs_client 
# wget http://php-httpsqs-client.googlecode.com/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:         20041225 Zend Module Api No:      20060613 Zend Extension Api No:   220060519 Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. 根据网上的解决办法是: yum install m4 yum 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 = new HttpSQS($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 = new HttpSQS($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 = new HttpSQS($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'];

?>

相关文章:

Windows Server 2012 系统群集

Windows Server 2012 系统群集本次将测试Windows Server 2012 系统群集功能。实验环境&#xff1a;4台服务器都为Windows Server 2012 DataCenter操作系统SRV2012服务器安装iSCSI目标服务器角色并配置2块虚拟磁盘给两台群集服务器共享使用。群集服务器安装群集功能&#xff0c;…

Python 中最强大的错误重试库

作者 | 费弗里来源丨Python大数据分析1 简介我们在编写程序尤其是与网络请求相关的程序&#xff0c;如调用web接口、运行网络爬虫等任务时&#xff0c;经常会遇到一些偶然发生的请求失败的状况&#xff0c;这种时候如果我们仅仅简单的捕捉错误然后跳过对应任务&#xff0c;肯定…

Spring Cloud云架构 - SSO单点登录之OAuth2.0登录流程(2)

上一篇是站在巨人的肩膀上去研究OAuth2.0&#xff0c;也是为了快速帮助大家认识OAuth2.0&#xff0c;闲话少说&#xff0c;我根据框架中OAuth2.0的使用总结&#xff0c;画了一个简单的流程图&#xff08;根据用户名密码实现OAuth2.0的登录认证&#xff09;&#xff1a; 上面的图…

php的POSIX 函数以及进程测试

参考&#xff1a;http://cn.php.net/manual/zh/ref.posix.php <?phpecho posix_getpid(); //8805sleep(10);?>再用 #ps -ax这个时候如果多开开个浏览器请求&#xff0c;就会发现Apache自动增加了几个新的进程我们发现并非一直请求同一个进程重启apache # /usr/local/ap…

CAS (10) —— JBoss EAP 6.4下部署CAS时出现错误exception.message=Error decoding flow execution的解决办法...

CAS (10) —— JBoss EAP 6.4下部署CAS时出现错误exception.messageError decoding flow execution的解决办法 jboss版本: jboss-eap-6.4-CVE-2015-7501 jdk版本: 1.7.0_79 cas版本: cas 4.1.3 参考来源: Nabble: exception.messageErrordecodingflowexecution Nabble: Caused …

昇思MindSpore1.6发布 AI开发者体验再升级

智能时代&#xff0c;AI技术正在发挥至关重要的作用&#xff0c;而开源的深度学习框架不仅能够降低AI开发者的门槛&#xff0c;而且能够极大节省成本与时间&#xff0c;成为创新的重要推手。2022年3月26-27日&#xff0c;昇思MindSpore TechDay活动线上成功举办&#xff0c;包含…

深入解析:TRUNCATE TABLE 的内部原理解析与恢复思路

摘要 众所周知&#xff0c;truncate table 是一种快速清空表内数据的一种方式&#xff0c;与 delete 方式不同&#xff0c;truncate 只产生非常少的 redo 和 undo&#xff0c;就实现了清空表数据并降低表 HWM 的功能。本文主要围绕 truncate table 的实现原理和 truncate table…

Linux exec与重定向

exec和source都属于bash内部命令&#xff08;builtins commands&#xff09;&#xff0c;在bash下输入man exec或man source可以查看所有的内部命令信息。 bash shell的命令分为两类&#xff1a;外部命令和内部命令。外部命令是通过系统调用或独立的程序实现的&#xff0c;如se…

俄罗斯 Android 系统受限,或将转用 HarmonyOS!

整理 | 郑丽媛出品 | CSDN近一个月来&#xff0c;受当前局势影响&#xff0c;部分底层工具、基础软件、开源项目已相继宣布在俄罗斯停服&#xff0c;期间不少人因此担忧&#xff1a;同出自美国且占据极大智能手机市场的 Android 和 iOS 是否会趁机“作乱”&#xff1f;结果&…

Ios应用网络安全之https

戴维营教育原创文章&#xff0c;转载请注明出处。我们的梦想是做最好的iOS开发培训&#xff01;iOS应用网络安全之HTTPS1. HTTPS/SSL的基本原理安全套接字层 (Secure Socket Layer, SSL) 是用来实现互联网安全通信的最普遍的标准。Web 应用程序使用 HTTPS&#xff08;基于 SSL …

云原生应用的10大关键属性

2019独角兽企业重金招聘Python工程师标准>>> “云原生”是用于描述基于容器的环境的术语&#xff0c;而Kubernetes是一个运行云原生应用程序工作负载的理想平台。 开发人员在设计云原生应用程序时&#xff0c;一定要牢记本文内这10个关键属性&#xff01; “云原生&…

grep 正则表达式及选项以及注意

说明&#xff1a;在原文基础上稍作了修改grep命令简介&#xff1a; 在ex编辑器&#xff08;我没用过&#xff09;中&#xff0c;启动ex编辑器后要查找某个字符串时&#xff0c;在ex的命令提示符后键入::/pattern/p:/g/pattern/pgrep这个名字就由来如此。其中p的含义是print&…

iOS_25彩票_幸运转盘

终于效果图: 各个view的关系图: 背景圆盘(须要扣图处理)LuckyBaseBackground.png 盖在背景圆盘上面的转盘 LuckyRotateWheel.png 代表一个星座或生肖的button背景图片 要创建12个,并以最下方中点为锚点进行旋转 对背景圆盘进行扣图,并在其上面盖上转盘图片的核心代码 在自己定义…

Python 自动化办公之 Excel 对比工具

作者 | 周萝卜来源丨萝卜大杂烩今天我们继续分享真实的自动化办公案例&#xff0c;希望各位 Python 爱好者能够从中得到些许启发&#xff0c;在自己的工作生活中更多的应用 Python&#xff0c;使得工作事半功倍&#xff01;需求由于工作当中经常需要对比前后两个 Excel 文件&am…

jQuery简单实现iframe的高度根据页面内容自适应的方法(转)

本文实例讲述了jQuery简单实现iframe的高度根据页面内容自适应的方法。分享给大家供大家参考&#xff0c;具体如下&#xff1a;方式1&#xff1a;//注意&#xff1a;下面的代码是放在和iframe同一个页面中调用 $("#iframeId").load(function () {var mainheight $(t…

linux wc 命令简介

此wc命令不是让大家没有食欲的地方。而是linux下一个简单的小命令。NAMEwc — word, line, character, and byte countSYNOPSISwc [-clmw] [file ...]下面让我们来简单的看一下其支持的参数及其代表的含义。 参数及含义 参数含义-c显示文件的Bytes数(字节数)-l将每个文件的行数…

这个插件竟打通了Python和Excel,还能自动生成代码!

作者 | 云朵君来源丨数据STUDIO加载一个Jupyter插件后&#xff0c;无需写代码就能做数据分析&#xff0c;还帮你生成相应代码&#xff1f;没错&#xff0c;只需要加载这个名为Mito的小工具包&#xff0c;用Python做数据分析&#xff0c;变得和用Excel一样简单&#xff1a;介绍以…

集合list set Map问题

2019独角兽企业重金招聘Python工程师标准>>> ####集合list set Map的个人理解 首先集合说的对一类数据的存储容器&#xff0c;对象都是引用类型并不是基本数据类型 collection 接口 list和set都需实现它 collections 抽象了一些集合的基本功能&#xff0c;reverse s…

python学习第四课

#!/user/bin/env python#-*-coding:utf-8-*-# 一、字符串魔法# &#xff08;1&#xff09;.isalpha()是否是字母或汉字。# 例&#xff1a;# a"张san22"# b"张三lisi"# va.isalpha()# v1b.isalpha()# print(v)# print(v1)# 因为a里含有数字&#xff0c;结果…

PHP 截取字符串专题

1. 截取GB2312中文字符串<?php< ?php//截取中文字符串functionmysubstr($str, $start, $len){$tmpstr ""; $strlen $start $len; for($i 0; $i< $strlen; $i){if(ord(substr($str, $i, 1))> 0xa0){$tmpstr. substr($str, $i, 2); $i; }else$tm…

​GPT-3好“搭档”:这种方法缓解模型退化,让输出更自然

作者 | LZM来源丨数据实战派文本生成对于许多自然语言处理应用来说都是非常重要的。但神经语言模型的基于最大化的解码方法&#xff08;如 beam search&#xff09;往往导致退化解&#xff0c;即生成的文本是不自然的&#xff0c;并且常常包含不必要的重复。现有的方法通过采样…

(Question)CSS中position的绝对定位问题

RT,绝对定位相对于定位的元素存在是哪里&#xff1f; https://yunpan.cn/crjSMTiak2srZ 访问密码 1570转载于:https://www.cnblogs.com/LiuChunfu/p/5139958.html

BZOJ 4817: [Sdoi2017]树点涂色(LCT+树剖+线段树)

题目描述 Bob有一棵 nn 个点的有根树&#xff0c;其中1号点是根节点。Bob在每个点上涂了颜色&#xff0c;并且每个点上的颜色不同。 定义一条路径的权值是&#xff1a;这条路径上的点&#xff08;包括起点和终点&#xff09;共有多少种不同的颜色。 Bob可能会进行这几种操作&am…

ls -l |wc -l命令多统计一行

#ls -l |wc -l注意&#xff1a;总用量也占用1行&#xff0c;所以统计出来的是14而不是13其他网友提醒 #ls -l |wc -l 就统计实际的行&#xff0c;放大就看出效果1和l不同

驱动数字经济加速,摩尔线程发布全新元计算架构MUSA和GPU产品

2022年3月30日&#xff0c;北京——摩尔线程今天举行主题为“元动力 创无限”的春季发布会。摩尔线程创始人兼CEO张建中解读了“元计算”这一产业趋势&#xff0c;并发布全新架构及系列重磅新品&#xff0c;包括&#xff1a;MUSA&#xff08;Moore Threads Unified System Arch…

HDU 4869 Turn the pokers(思维+组合公式+高速幂)

Turn the pokers 大意&#xff1a;给出n次操作&#xff0c;给出m个扑克。然后给出n个操作的个数a[i]&#xff0c;每一个a[i]代表能够翻的扑克的个数&#xff0c;求最后可能出现的扑克的组合情况。Hint Sample Input&#xff1a; 3 3 3 2 3 For the this example: 0 express fac…

马云打响本地生活消费攻坚战,饿了么获手淘一级入口,美团危险了

8月2日&#xff0c;细心的网友可以发现&#xff0c;手机淘宝App首页已上线“饿了么外卖”&#xff0c;饿了么成为手机淘宝首页的10个默认入口之一。这也就意味着以后手机淘宝用户可以通过淘宝首页新入口进入外卖服务&#xff0c;在应用内直接完成由饿了么提供的订餐外卖服务。 …

Linux文件,文件描述符以及dup()和dup2()

一.Linux中文件 可以分为4种&#xff1a;普通文件、目录文件、链接文件和设备文件。1、普通文件是用户日常使用最多的文件&#xff0c;包括文本文件、shell脚本、二进制的可执行和各种类型的数据。ls -lh 来查看某个文件的属性&#xff0c;可以看到有类似 -rw-r--r-- &#xff…

摩尔线程推出首款数据中心级全栈功能GPU:MTT S2000

2022年3月30日&#xff0c;北京——摩尔线程正式推出首款基于其先进架构MUSA统一系统架构&#xff08;Moore Threads Unified System Architecture&#xff09;打造的数据中心级多功能GPU产品MTT S2000。摩尔线程MTT S2000基于其第一代MUSA架构GPU芯片苏堤研发制成&#xff0c;…

jquery 获取 outerHtml 包含当前节点本身的代码

在开发过程中&#xff0c;jQuery.html() 是获取当前节点下的html代码&#xff0c;并不包含当前节点本身的代码&#xff0c;然后我们有时候确需要&#xff0c;找遍jQuery api文档也没有任何方法可以拿到。 看到有的人通过parent().html()&#xff0c;如果当前元素没有兄弟元素还…