PHP code example of pidongqq / codeigniter-queue-job

1. Go to this page and download the library: Download pidongqq/codeigniter-queue-job library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pidongqq / codeigniter-queue-job example snippets


class Task extends Pidong\Queue\QueueController
{
  \\your business code
}

$this->dispatch($queueName, $controller, $method, $params);
//$queueName (string): 是队列名称(你可能需要不同的队列)
//$controller/$method(string): 队列最终执行会在你指定的$controller/$method中处理
//$params (array): 是你希望在队列中存的信息或参数
//在$controller/$method获取参数使用$_POST

$this->onConnection($connectName)->dispatch($queueName, $controller, $method, $params);
//使用指定连接时,你需要现在config/queue.php添加该连接(该配置文件来自 安装 第3步)
//!!!注意:要先使用onConnection再dispatch

  $config['queue_connections'] = [
      'default' => [
          'host'     => 'localhost',
          'port'     => '6379',
          'password' => ''
      ]
  ];
  //可以按照此格式,添加更多连接

    $ php public/index.php Pidong/Queue/Controller/launch //开启后台程序,监听任务并执行worker
    
    //只启动监听程序
    $ php public/index.php Pidong/Queue/Controller/listen
    //只启动worker
    $ php public/index.php Pidong/Queue/Controller/worker