本文共 3120 字,大约阅读时间需要 10 分钟。
<?php $pheanstalk=require 'beanstalkd.php'; print_r($pheanstalk->status); print_r($pheanstalk->listTubes()); #查询目前存在的管道 print_r($pheanstalk->statsTube('newUsers')); #查询newUsers管道详情 php -f demo.php Array( [0]=>default #默认管道 [1]=>newUsers #自定义管道 )[name]=>newUsers #当前管道名[current-jobs-urgent]=>0 #当前管道里存在优先级的任务数[current-jobs-ready]=>2 #当前管道里等待的任务数字[current-jobs-reserved]=>0 #。。。保留任务数[current-jobs-delayed]=>0 #。。。等待状态的任务数[current-jobs-buried]=>0 #。。。保留状态的任务数[total-jobs]=>2 #总任务统计[current-using]=>0 #当前有多少生产者在使用该管道 usetube命令统计[current-watching]=>0 #当前有多少消费者在使用该管道 watch 命令统计[current-waiting]=>0 #当前有多少消费者在等待任务到来 reserved指令统计[current-delete]=>0[current-pause-tube]=>0[pause]=>0[pause-time-left]=>0<?php $pheanstalk=require 'beanstalkd.php'; $pheanstalk->useTube('newUsers')->put('test'); print_r($pheanstalk->statsTube(newUsers)); #php -f demo.php <?php $pheanstalk=require 'beanstalkd.php'; $job=$pheanstalk->watch('newUsers')->resers(); $stats=$pheanstalk->statsJob($job); print_r($stats); #php -f demo.php
Array( [id]=>51 当前任务的job ID [tube]=>newUsers 当前任务所在的管道名字 [state]=>reserved 当前任务的状态是reserved [pri]=>1024 当前任务的优先级 越小越优先 [age]=>11376 任务从创建到现在活了多久 [delay]=>0 当前任务设置延时的时间 [ttr]=>60 ttr 时间 [time-left]=>59 当前任务在reserved状态已经维持了多久 ttr只有60秒,超过60秒任务就会被放回管道 [file]=>4 bin-log 存储在日志中了 [reserves]=>12 当前reserves状态的次数 一直ttr超时就会被消费多次,这个任务就好被reserved n 次 [timeouts]=>0 reversed超时的次数 [releases]=>0 release方法重设任务的状态 [buries]=>0 被预留的次数 [kicks]=>0 任务从预留状态准备状态)<?php $pheanstalk=require 'beanstalkd.php'; $job=$pheanstalk->peek(51); $stats=$pheanstalk->statsJob($job); print_r($stats); ?> #php -f demo.php
Array( [id]=>51 当前任务的job ID [tube]=>newUsers 当前任务所在的管道名字 [state]=>reserved 当前任务的状态是reserved [pri]=>1024 当前任务的优先级 越小越优先 [age]=>11376 任务从创建到现在活了多久 [delay]=>0 当前任务设置延时的时间 [ttr]=>60 ttr 时间 [time-left]=>59 当前任务在reserved状态已经维持了多久 ttr只有60秒,超过60秒任务就会被放回管道 [file]=>4 bin-log 存储在日志中了 [reserves]=>12 当前reserves状态的次数 一直ttr超时就会被消费多次,这个任务就好被reserved n 次 [timeouts]=>0 reversed超时的次数 [releases]=>0 release方法重设任务的状态 [buries]=>0 被预留的次数 [kicks]=>0 任务从预留状态准备状态)工具类 :bean.class.php
_initBeanstalkd($conf['host'],$conf['port']); } //连接beanstalkd privated function _initBeanstalkd($host='127.0.0.1',$port=11300){ $this->_beanstalkd=new Pheanstalk\Pheanstalk($host,$port); } privated function _getBeanstalkdInstance(){ return $this->_beanstalkd; } privated function _kvOutput($val){ if($val instanceof \Pheanstalk\Job){ printf("jobId:%s message:%s".PHP_EOL,$val->getId(),$val->getData()); } }}?>
转载地址:http://koboi.baihongyu.com/