beanstalkd队列@year12

安装
进入目录直接make && make install (默认安装 /usr/local/bin)
 
beanstalkd -l 127.0.0.1 -p 11300 & //启动
-l ip -p 端口
 
composer require pda/pheanstalk
composer php操纵beanstalkd 类
 
Pheanstalk\Response\ArrayResponse Object
(
[_name:Pheanstalk\Response\ArrayResponse:private] => OK
[storage:ArrayObject:private] => Array
(
[name] => default //当前管道名称
[current-jobs-urgent] => 0 //存在的优先级的任务数
[current-jobs-ready] => 0 就绪状态的任务数
[current-jobs-reserved] => 0 读出
[current-jobs-delayed] => 0 延时任务数
[current-jobs-buried] => 0 预留状态的任务数
[total-jobs] => 0 当前管道里的任务数
[current-using] => 1 当前有多少个生成者在使用这个任务
[current-watching] => 1 当前有多少个消费者在使用这个任务
[current-waiting] => 0 当前有多少个消费着在等待任务的到来
[cmd-delete] => 0 删除
[cmd-pause-tube] => 0
[pause] => 0
[pause-time-left] => 0
)
 
)
 
Pheanstalk\Response\ArrayResponse Object
(
[_name:Pheanstalk\Response\ArrayResponse:private] => OK
[storage:ArrayObject:private] => Array
(
[id] => 1
[tube] => default
[state] => reserved
[pri] => 1024 //job优先级(默认1024,数值越小优先级越高)
[age] => 165 //任务从创建到现在的秒数
[delay] => 0 //等待的整数秒数 就绪队列。在这段时间内,工作将处于“延迟”状态。
[ttr] => 60 //允许运行时间 - 超时将释放。
[time-left] => 59 //时间限制还有多少秒
[file] => 0 //
[reserves] => 1 //reserves状态次数
[timeouts] => 0 //ttr 超时次数
[releases] => 0 //重设任务状态
[buries] => 0 //被预留的次数
[kicks] => 0 //从预留替回到ready状态
)
 
)
 
pheanstalk 常用方法(只是个工具而已!)
 
//连接beanstalk服务
$pheanstalk = new Pheanstalk('127.0.0.1',11300);
 
//return $pheanstalk;
 
//显示队列状态
//print_r($pheanstalk->stats());
 
//显示当前存在的管道
//print_r($pheanstalk->listTubes());
 
//显示当前管道状态
print_r($pheanstalk->statsTube('default'));
 
//指定使用哪个管道
//$pheanstalk->useTube('default');
//$pheanstalk->useTube('default')->put('test');
 
//put方法
//$pheanstalk->put(job,pri,delay,ttr);
//$pheanstalk->putInTube('default',888,优先级(默认1024),延迟,任务超时重发(默认60s));
 
//获取指定管道的任务
//watch为监听,reserve 为获取
//$job = $pheanstalk->watch('default')->reserve();
 
//获取任务内容
//$data = $pheanstalk->getData($job);
 
//根据任务id来获取任务
//$job = $pheanstalk->peek(20);
 
//获取该任务状态
//$stats = $pheanstalk->statsJob($job);
//print_r($stats);
 
//让该任务状态从reserve->ready。
//$pheanstalk->release($job);
 
//预留该任务
//$pheanstalk->bury($job);
 
//读出该管道的1个预留任务
//$job = $pheanstalk->peekBuried('default');
 
////将该任务放回ready
//$pheanstalk->kickJob($job);
 
//批量将JOB-ID小于1000的拿去放回ready
//$pheanstalk->kick(1000);
 
//删除任务
//$pheanstalk->delete($job);
 
///读出该管道的1个ready任务
//$job = $pheanstalk->peekReady('default');
 
//读出该管道一个定时Delayed任务
//$job = $pheanstalk->peekDelayed('default');
 
//设置整个管道暂停,设置延迟时间(s)
//$pheanstalk->pauseTube('default',10);
//
//取消整个管道暂停,立即被消费
//$pheanstalk->resumeTube('default');
 
//增加任务ttr时间,重新计算ttr时间
//$pheanstalk->touch($job);
 
 
 
 
posted @ 2017-12-01 16:45  year12  阅读(488)  评论(0编辑  收藏  举报