最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

Lavarel异步队列的使用

维修 admin 32浏览 0评论

Lavarel异步队列的使用

系统为window

启动队列:

php artisan queue:listen

设置队列类
.env文件需设置:QUEUE_CONNECTION=redis

<?phpnamespace App\Jobs;use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;class SendEmail implements ShouldQueue
{use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;protected $email;/*** Create a new job instance.** @param  string  $email* @return void*/public function __construct($email){$this->email = $email;}/*** Execute the job.** @return void*/public function handle(){Log::info($this->email);}}

使用

use App\Jobs\SendEmail;
class TestController extends Controller
{public function test() {Log::info('开始');$t = now()->addSeconds(10);//设置延迟时间SendEmail::dispatch('@qq')->delay($t);Log::info('结束');}
}

Lavarel异步队列的使用

系统为window

启动队列:

php artisan queue:listen

设置队列类
.env文件需设置:QUEUE_CONNECTION=redis

<?phpnamespace App\Jobs;use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;class SendEmail implements ShouldQueue
{use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;protected $email;/*** Create a new job instance.** @param  string  $email* @return void*/public function __construct($email){$this->email = $email;}/*** Execute the job.** @return void*/public function handle(){Log::info($this->email);}}

使用

use App\Jobs\SendEmail;
class TestController extends Controller
{public function test() {Log::info('开始');$t = now()->addSeconds(10);//设置延迟时间SendEmail::dispatch('@qq')->delay($t);Log::info('结束');}
}

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论