zoukankan      html  css  js  c++  java
  • tp5.1使用队列

    1.基础条件

    thinkphp5.1

    think-queue2.04

    2.安装think-queue

    composer require topthink/think-queue

    3.写配置文件

     一:项目所在目录/www/edu/infoaa/config下面的queue.php文件写入配置

    return [
        'connector' => 'Redis',
        'expire' =>60,
        'default'=>"test_queue",
        'host' => '127.0.0.1',
        'port' =>6379,
        'password'=>'',
        'select'=>0,
        'timeout'=>0,
        'persistent'=>false,
    ];

    4.生产者的代码示范

       public function Info(){
            $name="testinfo";//队列名字
            $data=["ts"=>time(),"name"=>"lisi"];//内容
            $jobHandle="appjobDemo";//消费者代码
            $bol=Queue::push($jobHandle,$data,$name);
            var_dump($bol);
       }

     备注:使用浏览器访问http://ip地址/course/info

    5. 消费者代码实例

     一:项目目录下/www/edu/infoaa/application/job建立Demo.php文件

    二:代码实例

    namespace appjob;
    use thinkqueueJob;
    class Demo
    {
        // 默认执行的方法
        public function fire(Job $job, $data)
        {
       //写自己的默认的业务逻辑 print(
    "<info>Hello Job Started. job Data is: ".var_export($data,true)."</info> "); return true; } } ?>

    6.运行队列

     php think queue:work --queue testinfo

    7.结果展示

    <info>Hello Job Started. job Data is: array (
      'ts' => 1627268104,
      'name' => 'lisi',
    )</info> 
  • 相关阅读:
    __weak与__block修饰符区别
    Socket 记录
    Python yaml文件中文读取写入
    Xshell 连接 本地虚拟机
    MySQL查询学生表
    Python Excel读写操作
    pytest mark标记运行
    pytest 参数化
    pytest xfail参数详解
    pytest 失败截图
  • 原文地址:https://www.cnblogs.com/zh718594493/p/15060984.html
Copyright © 2011-2022 走看看