tp5.1&think-queue队列

        一、 先下载Composer

        1 Wondows 平台上,我们只需要下载 [Composer-Setup.exe] (https://getcomposer.org/Composer-Setup.exe) 后,一步步安装即可。 需要注意的是你需要开启 openssl 配置,我们打开 php 目录下的 php.ini, 将 extension=php_openssl.dll 前面的分号去掉就可以了。

        冷暖自知一抹茶ck

        2 安装成功后,我们可以通过win+R打开命令窗口(cmd) 输入 composer -- version 命令来查看是否安装成功:

        冷暖自知一抹茶ck

        3 打开管理员控制器,找到网站根目录。

        在win+R打开命令窗口(cmd) 找到自己的集成环境的网站访问目录,再粘 贴“composer create-project topthink/think tp51 5.1”这串命令,然后这段命令tp51是文件夹名称,这里我们取的是5.1版本,也就是下载thinkphp5.1到这个 文件夹里面。

        冷暖自知一抹茶ck

        4 thinkphp5.1 不做过多的介绍

        冷暖自知一抹茶ck

        5 think-queue下载

        5.1 composer require topthink/think-queue 

        5.2 可能会出现composer 版本过期 首先更新composer版本 执行命令 composer selfupdate 或者 composer self-update 

        5.3 下载think-queue消息队列 composer require topthink/think-queue 1.1.4 (由于框架版本原因可以选择适合的版本 tp5.1 框架 可以安装1.1.4 1.1.6 ...)

        冷暖自知一抹茶ck

        5.4 验证是否安装成功 php think queue:work -h

        冷暖自知一抹茶ck

        6 写点代码看看think-queue的运行过程

        6.1 建立一个数据库

CREATE TABLE `hbjh_test` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`age` int(10) NOT NULL DEFAULT '0' COMMENT '年级',
`create_time` int(10) NOT NULL DEFAULT '0' COMMENT '创建时间',
`attempts` int(10) NOT NULL DEFAULT '0' COMMENT '执行的次数',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

        6.2 queue默认不使用redis缓存不建议使用Database , 调整queue配置文件

        冷暖自知一抹茶ck

        6.3 写点代码体会一下流程

        冷暖自知一抹茶ck


        冷暖自知一抹茶ck


        6.4 运行 index/push 报错 解决一下 Queue里面的类报错信息 

        自己体会其中的运行流程.....



队列使用的一些说明:

        获取帮助:  php think queue:work --help

PS D:\web\project> php think queue:work --help
Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: 127.0.0.1:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(
Usage:
  queue:work [options]

Options:
      --queue[=QUEUE]    The queue to listen on
      --daemon           Run the worker in daemon mode
      --delay[=DELAY]    Amount of time to delay failed jobs [default: 0]
      --force            Force the worker to run even in maintenance mode
      --memory[=MEMORY]  The memory limit in megabytes [default: 128]
      --sleep[=SLEEP]    Number of seconds to sleep when no job is available [default: 3]
      --tries[=TRIES]    Number of times to attempt a job before logging it failed [default: 0]
  -h, --help             Display this help message
  -V, --version          Display this console version
  -q, --quiet            Do not output any message
      --ansi             Force ANSI output
      --no-ansi          Disable ANSI output
  -n, --no-interaction   Do not ask any interactive question
  -v|vv|vvv, --verbose   Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

        指令:

queue:restart  队列重启
queue:work  队列执行
queue:listen 队列监听
queue:subscribe 队列订阅

        后台遍历执行:

php think queue:work --daemon
#或者
php think queue:listen

        queue:work --daemon和queue:listen的区别:

        queue:work --daemon 在修改job下面的代码后需要重启服务,利用的是缓存方式(相当于常驻内存),速度非常高效!!!推荐。         queue:listen 修改job下面代码实时生效,每次都会重新载入框架,相对来说更消耗性能,调试时使用或者不行经常重启时采用

php think queue:work --daemon --queue  abc_queue &

参数说明


& 后台运行

--daemon 是否循环执行,如果不加该参数则该命令处理完下一个消息就退出。

--queue abc_queue 要处理的队列的名称

--delay 0 如果本次任务执行抛出异常且任务未被删除时,设置其下次执行前延迟多少秒,默认为0。

--force 系统处于维护状态时,是否仍然处理任务,并未找到相关说明。

--memory 128 该进程允许使用的内存上限,以M为单位。

--sleep 3 如果队列中无任务则sleep多少秒后重新检查(work+daemon模式)或退出(listen或非daemon模式)

--tries 2 如果任务已经超过尝试次数上限,则触发“任务尝试数超限”事件,默认为0。





        转:https://www.cnblogs.com/liquan-1234/p/think-queue.html 

        参考:

                 https://www.cnblogs.com/Daneil/p/11670346.html   

                 https://blog.csdn.net/weixin_42411512/article/details/122977132     


        附:topthink/think-queue 官方扩展包    (tp5.1 最低需要 topthink/think-queue 2.0)

冷暖自知一抹茶ck
请先登录后发表评论
  • 最新评论
  • 总共0条评论