newiep/httpsqs

基于http的简单队列服务

dev-master 2016-10-14 03:22 UTC

This package is not auto-updated.

Last update: 2024-11-09 19:38:39 UTC


README

#HttpSQS (基于HTTP协议的简单队列服务) 使用示例

安装

$ composer require newiep/httpsqs

初始化操作

<?php
use Newiep\HttpSQS;

$httpsqs = new HttpSQS($host, $port, $auth, $charset);

入队操作

$httpsqs->put('newiep','example1'); //true

出队操作

可以使用get()方法,该方法只返回队列中的值:

//get: 如果队列为空 返回 "HTTPSQS_GET_END"
$result = $httpsqs->get('newiep'); // example1

也可以使用gets()方法,该方法不仅返回队列中的值还有该值对应的位置:

//gets: 队列为空返回 array('pos'=>null, 'data'=> "HTTPSQS_GET_END" );

$result = $httpsqs->gets('newiep'); // array('pos'=>1, 'data'=>'example1');

查看队列状态

$result = $httpsqs->status('newiep');

默认返回的结果是字符串形式:

//字符串形式
 HTTP Simple Queue Service v1.7 
------------------------------ 
Queue Name: newiep 
Maximum number of queues: 1000000 
Put position of queue (1st lap): 13 
Get position of queue (1st lap): 12 
Number of unread queue: 1 

也支持json格式:

//json 格式
$result = $httpsqs->status('newiep', 'status_json');

返回:

{"name":"newiep","maxqueue":1000000,"putpos":45,"putlap":1,"getpos":6,"getlap":1,"unread":39}

查看队列指定位置的值

$result = $httpsqs->view('newiep', 1);  //  example1

重置指定队列

//将队列重置,从开始位置重新写入

$result = $httpsqs->reset('newiep'); //true

更改指定队列的最大队列数量,默认 100万条

//修改的数值需满足条件:($num >=10 && $num <= 1000000000)

$result = $httpsqs->maxqueue('newiep', 1000); //true

$result = $httpsqs->maxqueue('newiep', 1); //false

不停止服务的情况下,修改定时刷新内存缓冲区内容到磁盘的间隔时间

// 默认间隔时间:5秒

$result = $foo->synctime(10); //true