- 安装 think-queue
composer require topthink/think-queue 1.1.4
不加版本号 默认安装的最新的queue ,适用于tp6.0。 使用tp5.0 只需要1.1.4 即可,不加版本号会报错,提示版本不匹配
2.配置文件
内容编辑修改
return [
'connector' => 'Redis', // Redis 驱动
'expire' => null, // 任务的过期时间,默认为60秒; 若要禁用,则设置为 null
'default' => 'default', // 默认的队列名称
'host' => '127.0.0.1', // redis 主机ip
'port' => 6379, // redis 端口
'password' => '', // redis 密码
'select' => 0, // 使用哪一个 db,默认为 db0
'timeout' => 0, // redis连接的超时时间
'persistent' => false, // 是否是长连接
];
3.生产者(入队)

把你需要处理的信息,加入到队列当中;
4.消费者(出队)

$isJobDone = this−>doHelloJob(this->doHelloJob(this−>doHelloJob(data); 是你执行的逻辑方法;
- 操作命令
启动
php think queue:work --daemon --queue helloJobQueue
helloJobQueue 是你的队列名称 ,在生产者里面有设置;
加 --daemon 为循环执行,只有队列里面有你添加的数据有会一直执行
不加 单次执行,执行一次消费就会退出
停止
php think queue:restart
重启
php think queue:restart
php think queue:work
6.守护进程
使用 supervisor

260




被折叠的 条评论
为什么被折叠?



