Lavarel异步队列的使用

编程入门 行业动态 更新时间:2024-10-25 14:25:51

Lavarel异步<a href=https://www.elefans.com/category/jswz/34/1771257.html style=队列的使用"/>

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异步队列的使用

本文发布于:2023-11-16 01:27:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1611169.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:队列   Lavarel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!