httpsqs消息队列

安装:

    

在安装httpsqs之前要安装

  1. libevent-2.0.12-stable.tar.gz和okyocabinet-1.4.47.tar.gz  
  1. ulimit -SHn 65535  

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

  1. wget http://httpsqs.googlecode.com/files/libevent-2.0.12-stable.tar.gz##下载  
  2. tar zxvf libevent-2.0.12-stable.tar.gz##解压  
  3. cd libevent-2.0.12-stable/  
  4. ./configure --prefix=/usr/local/libevent-2.0.12-stable/  
  5. make  
  6. make install  
  7. cd ../  

安装tokyocabinet-1.4.47.tar.gz

  1. wget http://httpsqs.googlecode.com/files/tokyocabinet-1.4.47.tar.gz  
  2. tar zxvf tokyocabinet-1.4.47.tar.gz  
  3. cd tokyocabinet-1.4.47/  
  4. ./configure --prefix=/usr/local/tokyocabinet-1.4.47/  
  5. #注:在32位Linux操作系统上编译Tokyo cabinet,请使用./configure --enable-off64代替./configure,可以使数据库文件突破2GB的限制。  
  6. #./configure --enable-off64 --prefix=/usr/local/tokyocabinet-1.4.47/  
  7. make  
  8. make install  
  9. cd ../  

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

 

下面进行安装

  1. http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz安装开始;  
  2. wget  http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz  
  3. tar -xvzf bzip2-1.0.6.tar.gz  
  4. cd bzip2-1.0.6.  
  5. make  
  6.  make install  

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

 

下面进行安装

  1. http://www.winimage.com/zLibDll/zlib-1.2.5.tar.gz安装开始;  
  2. wget  http://www.winimage.com/zLibDll/zlib-1.2.5.tar.gz  
  3. tar -xvzf zlib-1.2.5.tar.gz  
  4. cd zlib-1.2.5.  
  5. ./configure  
  6. make  
  7. sudo make instal  

继续第2步骤 OK

 

3、安装httpsqs-1.7.tar.gz

    1. wget http://httpsqs.googlecode.com/files/httpsqs-1.7.tar.gz  
    2. tar zxvf httpsqs-1.7.tar.gz  
    3. cd httpsqs-1.7/  
    4. make  
    5. make install  
    6. cd ../  
<?php
/*
----------------------------------------------------------------------------------------------------------------
HTTP Simple Queue Service - httpsqs client class for PHP v1.7.1Author: 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
----------------------------------------------------------------------------------------------------------------
Useage:
<?php
include_once("httpsqs_client.php");
$httpsqs = new httpsqs($httpsqs_host, $httpsqs_port, $httpsqs_auth, $httpsqs_charset);
$result = $httpsqs->put($queue_name, $queue_data); //1. PUT text message into a queue. If PUT successful, return boolean: true. If an error occurs, return boolean: false. If queue full, return text: HTTPSQS_PUT_END
$result = $httpsqs->get($queue_name); //2. GET text message from a queue. Return the queue contents. If an error occurs, return boolean: false. If there is no unread queue message, return text: HTTPSQS_GET_END
$result = $httpsqs->gets($queue_name); //3. GET text message and pos from a queue. Return example: array("pos" => 7, "data" => "text message"). If an error occurs, return boolean: false. If there is no unread queue message, return: array("pos" => 0, "data" => "HTTPSQS_GET_END")
$result = $httpsqs->status($queue_name); //4. View queue status
$result = $httpsqs->status_json($queue_name); //5. View queue status in json. Return example: {"name":"queue_name","maxqueue":5000000,"putpos":130,"putlap":1,"getpos":120,"getlap":1,"unread":10}
$result = $httpsqs->view($queue_name, $queue_pos); //6. View the contents of the specified queue pos (id). Return the contents of the specified queue pos.
$result = $httpsqs->reset($queue_name); //7. Reset the queue. If reset successful, return boolean: true. If an error occurs, return boolean: false
$result = $httpsqs->maxqueue($queue_name, $num); //8. Change the maximum queue length of per-queue. If change the maximum queue length successful, return boolean: true. If  it be cancelled, return boolean: false
$result = $httpsqs->synctime($num); //9. Change the interval to sync updated contents to the disk. If change the interval successful, return boolean: true. If  it be cancelled, return boolean: false
?>
----------------------------------------------------------------------------------------------------------------*/class Httpsqs
{public $httpsqs_host;public $httpsqs_port;public $httpsqs_auth;public $httpsqs_charset;public function __construct($host='127.0.0.1', $port=1218, $auth='', $charset='utf-8') {$this->httpsqs_host = $host;$this->httpsqs_port = $port;$this->httpsqs_auth = $auth;$this->httpsqs_charset = $charset;return true;}public function http_get($query){$socket = fsockopen($this->httpsqs_host, $this->httpsqs_port, $errno, $errstr, 5);if (!$socket){return false;}$out = "GET ${query} HTTP/1.1\r\n";$out .= "Host: {$this->httpsqs_host}\r\n";$out .= "Connection: close\r\n";$out .= "\r\n";fwrite($socket, $out);$line = trim(fgets($socket));$header = $line;list($proto, $rcode, $result) = explode(" ", $line);$len = -1;$pos_value  = 0;while (($line = trim(fgets($socket))) != ""){$header .= $line;if (strstr($line, "Content-Length:")){list($cl, $len) = explode(" ", $line);}if (strstr($line, "Pos:")){list($pos_key, $pos_value) = explode(" ", $line);}   if (strstr($line, "Connection: close")){$close = true;}}if ($len < 0){return false;}$body = fread($socket, $len);$fread_times = 0;while(strlen($body) < $len){$body1 = fread($socket, $len);$body .= $body1;unset($body1);if ($fread_times > 100) {break;}$fread_times++;}//if ($close) fclose($socket);fclose($socket);$result_array["pos"] = (int)$pos_value;$result_array["data"] = $body;return $result_array;}public function http_post($query, $body){$socket = fsockopen($this->httpsqs_host, $this->httpsqs_port, $errno, $errstr, 1);if (!$socket){return false;}$out = "POST ${query} HTTP/1.1\r\n";$out .= "Host: {$this->httpsqs_host}\r\n";$out .= "Content-Length: " . strlen($body) . "\r\n";$out .= "Connection: close\r\n";$out .= "\r\n";$out .= $body;fwrite($socket, $out);$line = trim(fgets($socket));$header = $line;list($proto, $rcode, $result) = explode(" ", $line);$len = -1;while (($line = trim(fgets($socket))) != ""){$header .= $line;if (strstr($line, "Content-Length:")){list($cl, $len) = explode(" ", $line);}if (strstr($line, "Pos:")){list($pos_key, $pos_value) = explode(" ", $line);}   if (strstr($line, "Connection: close")){$close = true;}}if ($len < 0){return false;}$body = @fread($socket, $len);//if ($close) fclose($socket);fclose($socket);$result_array["pos"] = (int)$pos_value;$result_array["data"] = $body;return $result_array;}public function put($queue_name, $queue_data){$result = $this->http_post("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=put", $queue_data);if ($result["data"] == "HTTPSQS_PUT_OK") {return true;} else if ($result["data"] == "HTTPSQS_PUT_END") {return $result["data"];}return false;}public function get($queue_name){$result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=get");if ($result == false || $result["data"] == "HTTPSQS_ERROR" || $result["data"] == false) {return false;}return $result["data"];}public function gets($queue_name){$result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=get");if ($result == false || $result["data"] == "HTTPSQS_ERROR" || $result["data"] == false) {return false;}return $result;} public function status($queue_name){$result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=status");if ($result == false || $result["data"] == "HTTPSQS_ERROR" || $result["data"] == false) {return false;}return $result["data"];}public function view($queue_name, $queue_pos){$result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=view&pos=".$pos);if ($result == false || $result["data"] == "HTTPSQS_ERROR" || $result["data"] == false) {return false;}return $result["data"];}public function reset($queue_name){$result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=reset");if ($result["data"] == "HTTPSQS_RESET_OK") {return true;}return false;}public function maxqueue($queue_name, $num){$result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=maxqueue&num=".$num);if ($result["data"] == "HTTPSQS_MAXQUEUE_OK") {return true;}return false;}public function status_json($queue_name){$result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=status_json");if ($result == false || $result["data"] == "HTTPSQS_ERROR" || $result["data"] == false) {return false;}return $result["data"];}public function synctime($num){$result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=httpsqs_synctime&opt=synctime&num=".$num);if ($result["data"] == "HTTPSQS_SYNCTIME_OK") {return true;}return false;}
}
?>

  

转载于:https://www.cnblogs.com/canbefree/p/4126808.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/406722.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

找出数组中重复的数

/*问题描述&#xff1a;数组a[N]&#xff0c;存放了1至N-1个数&#xff0c;其中某个数重复一次。写一个函数&#xff0c;找出被重复的数字.时间复杂度必须为O(N)&#xff0c;函数原型&#xff1a;int do_dup(int a[], int N) */#include <stdio.h>// 返回数组中重复的数 …

vue-cli 4.x 配置 htmlWebpackPlugin.options.title

在 vue.config.js 中添加配置&#xff1a; // 修改或新增html-webpack-plugin的值&#xff0c;在index.html里面能读取htmlWebpackPlugin.options.titlechainWebpack: config >{config.plugin(html).tap(args > {args[0].title 你想要设置的title;return args;}) },

编程之美----子数组的最大乘积

问题&#xff1a;给定一个长度为N的整数数组&#xff0c;只允许用乘法&#xff0c;不能用除法&#xff0c;计算任意(N-1)个数的组合中乘积最大的一组&#xff0c;并写出算法的时间复杂度。 解法一&#xff1a;用一个数组保存从左边到右边前i个元素的乘积。用另一个数组保存从右…

android internet参数传递

当Activity与Activity/Service&#xff08;或其它情况&#xff09;有时与要进行参数传递&#xff0c;最常用也是最简单的方式就是通过Intent来处理。 看如下代码&#xff1a; Intent intent new Intent(...); Bundle bundle new Bundle(); bundle.putString("NAME&q…

vue获取前一个页面路由地址

可以使用&#xff1a; vue-router的beforeRouterEnter钩子 其实也就是一个路由守卫 <script> export default {data() {return {fromPath: "",};},beforeRouteEnter(to, from, next) {next((vm) > {// 通过 vm 访问组件实例,将值传入fromPathvm.fromPath …

自动化测试中Python与C/C++的混合使用

From: http://hi.baidu.com/sacmelody/blog/item/cf3ee7088d2112f036d12289.html 背景 项目的自动化测试中已经使用了基于Python脚本的框架&#xff0c;自动化过程中最关键的问题就是如何实现桩模块。运用 Python 强大的功能&#xff0c;实现任何桩模块都是可能的&#xff0c;但…

在IT的路上,我在成长

在IT的路上&#xff0c;我在成长。很荣幸地加入了博客园这个大家庭。 岁月的航船在不断航行&#xff0c;在成长的脚印我要深深留下&#xff0c;回首已往经历&#xff0c;发现自己成长的路上&#xff0c;将来也会有很多美好的回忆&#xff0c;以及丰硕的果实。转载于:https://ww…

React开发(149):ant design控制是否必填

<Form.Item label"原因">{getFieldDecorator(signInResson,form.getFieldsValue().signStatus QS_TESHU ||form.getFieldsValue().signStatus JS_TESHU? {initialValue: ,rules: [{ required: true, message: 请填写原因 }],}: { rules: [{ message: 请填写…

你如何摆平秋季问题皮肤

随着秋天的到来&#xff0c;不少MM的面部、身体的皮肤都出现了这样那样大大小小的问题。小编带着 网友们关注的“一箩筐”的问题&#xff0c;特别走访了成都市第二人民医院皮肤科路永红主任医师。让她从专业医师的角度来为大家上一堂课&#xff0c;专门讲解秋季问题皮肤如何预 …

display:none和visibility:hidden两者的区别

使用css让元素不可见的方法有很多种&#xff0c;裁剪、定位到屏幕外边、透明度变换等都是可以的。但是最常用两种方式就是设置元素样式为display: none或者visibility: hidden。很多公司的面试官也常常会问面试者这两者之间的区别。 display与元素的隐藏 如果给一个元素设置了…

python应用领域介绍

From: http://zhidao.baidu.com/question/62447250 Python作为一种功能强大且通用的编程语言而广受好评&#xff0c;它具有非常清晰的语法特点&#xff0c;适用于多种操作系统&#xff0c;目前在国际上非常流行&#xff0c;正在得到越来越多的应用。下面就让我们一起来看看它的…

汇编常见伪指令

汇编常见伪指令 转自: http://blog.chinaunix.net/uid-20547722-id-1647296.html 一、与宏有关的伪指令在宏定义时&#xff0c;为了满足某种特殊需要&#xff0c;汇编语言还提供了几个伪指令。 9.3.1 局部标号伪指令LOCAL 在宏定义体中&#xff0c;如果存在标号&#xff0c;则…

运维秘籍:防止数据丢失“六脉神剑”

服务器数据存储安全是保障服务器正常运行的重要的环节&#xff0c;同时也是企业网络信息化建设的核心。每一家企业的管理层人员都非常重视存储在服务器的重要数据&#xff0c;包括&#xff1a;各类管理中所产生的机密办公文件、经营中所积累的客户资料、研发中所涉及的重要文件…

CSS中设置border属性为0与none的区别

在我们设置CSS的时候&#xff0c;对标签元素不设置边框属性或者取消边框属性一般设置为&#xff1a;border:none;或border:0;两种方法均可。 border:none;与border:0;的区别体现有两点&#xff1a;一是理论上的性能差异&#xff1b;二是浏览器兼容性的差异。 1.性能差异 【b…

windows下Python+Editplus windows Python开发环境

From: http://www.jb51.net/softjc/34898.html 点评&#xff1a;Python的安装程序以及源代码可以从其官方网站http://www.python.org/获取。以Windows XP、Python 3.1.3为例&#xff0c;在Windows下安装Python的过程如下。&#xff08;1&#xff09;从Python官方网站 http://…

Lightbox JS v2.0

概要&#xff1a;Lightbox JS 是一个简单而又谦恭的用来把图片覆盖在当前页面上的脚本. 它能被快速安装并且运作于所有流行的浏览器.最新更新 Version 2.0图片集: 分组相关的图片并且能轻松的导航它们 视觉特效: 奇特的自适应调整 向后兼容: yes! 点击这里查看实例演示如何使用…