1. Go to this page and download the library: Download ctfang/swoft-queue 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/ */
ctfang / swoft-queue example snippets
namespace App\Job;
use Swoft\Log\Helper\CLog;
use Swoft\Log\Helper\Log;
use Swoft\Queue\Annotation\Mapping\Job;
use Swoft\Queue\JobAbstract;
use Swoole\Coroutine;
/**
* Class NewFeedJob
* @package App\Job
* @Job(queue="test",name="demo")
*/
class TestJob extends JobAbstract
{
/**
* 业务处理
*
* @param $msg
*/
public function handle($msg): void
{
$id = uniqid();
CLog::info($id." 启动 ".json_encode($msg));
Coroutine::sleep(5);
CLog::info($id." 结束 ");
}
}