docker下安装运行beanstalkd轻量级消息队列
1、首先在docker中下载beanstalkd源
sudo docker pull "schickling/beanstalkd:latest"
运行结果:
2、docker下运行beanstalkd消息队列
这里服务就运行成功了。
3、使用Pheanstalk连接beanstalkd消息队列
composer安装Pheanstalk工具类
composer install pda/pheanstalk
然后编写连接beanstalkd代码如下
<?php
include_once "vendor/autoload.php";
use Pheanstalk\Pheanstalk;
try{
$conn = new Pheanstalk('192.168.135.138',11301);
$stu =$conn->stats();
var_dump($stu);die;
}catch (Exception $e){
var_dump($e->getMessage())
}
返回数据为下面数据时,服务连接成功,可以正常使用该消息队列。
object(Pheanstalk\Response\ArrayResponse)
["_name":"Pheanstalk\Response\ArrayResponse":private]=>
string(2) "OK"
["storage":"ArrayObject":private]=>
array(48) {
["current-jobs-urgent"]=>
string(1) "0"
["current-jobs-ready"]=>
string(1) "0"
["current-jobs-reserved"]=>
string(1) "0"
["current-jobs-delayed"]=>
string(1) "0"
["current-jobs-buried"]=>
string(1) "0"
["cmd-put"]=>
string(1) "0"
["cmd-peek"]=>
string(1) "0"
["cmd-peek-ready"]=>
string(1) "0"
["cmd-peek-delayed"]=>
string(1) "0"
["cmd-peek-buried"]=>
string(1) "0"
["cmd-reserve"]=>
string(1) "0"
["cmd-reserve-with-timeout"]=>
string(1) "0"
["cmd-delete"]=>
string(1) "0"
["cmd-release"]=>
string(1) "0"
["cmd-use"]=>
string(1) "0"
["cmd-watch"]=>
string(1) "0"
["cmd-ignore"]=>
string(1) "0"
["cmd-bury"]=>
string(1) "0"
["cmd-kick"]=>
string(1) "0"
["cmd-touch"]=>
string(1) "0"
["cmd-stats"]=>
string(1) "2"
["cmd-stats-job"]=>
string(1) "0"
["cmd-stats-tube"]=>
string(1) "0"
["cmd-list-tubes"]=>
string(1) "0"
["cmd-list-tube-used"]=>
string(1) "0"
["cmd-list-tubes-watched"]=>
string(1) "0"
["cmd-pause-tube"]=>
string(1) "0"
["job-timeouts"]=>
string(1) "0"
["total-jobs"]=>
string(1) "0"
["max-job-size"]=>
string(5) "65535"
["current-tubes"]=>
string(1) "1"
["current-connections"]=>
string(1) "1"
["current-producers"]=>
string(1) "0"
["current-workers"]=>
string(1) "0"
["current-waiting"]=>
string(1) "0"
["total-connections"]=>
string(1) "2"
["pid"]=>
string(1) "1"
["version"]=>
string(4) "1.10"
["rusage-utime"]=>
string(8) "0.034852"
["rusage-stime"]=>
string(8) "0.047693"
["uptime"]=>
string(4) "1370"
["binlog-oldest-index"]=>
string(1) "0"
["binlog-current-index"]=>
string(1) "0"
["binlog-records-migrated"]=>
string(1) "0"
["binlog-records-written"]=>
string(1) "0"
["binlog-max-size"]=>
string(8) "10485760"
["id"]=>
string(16) "984cd0cefa2bb0ee"
["hostname"]=>
string(12) "22b1eaea201b"
}
}
|