一定时间后在Laravel触发事件或听众 [英] Fire Event or listener after certain time in Laravel

查看:64
本文介绍了一定时间后在Laravel触发事件或听众的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在一定时间后在Laravel中触发事件或侦听器,我的想法是在用户注册后,有一个侦听器在一分钟后发送邮件,这种情况下cron不是解决方案.

Is it possible to Fire Event or listener after certain time in Laravel, my idea is to have one listener for sending mails after one minute, after user registration, cron isnt solution for this case.

推荐答案

在这种情况下,工作将是一个更好的选择.老实说,在应用程序中触发逻辑时,排队的工作更适合这种逻辑.

In this case a job would be a better options. To be honest queued jobs when firing logic within your application is more suited for this kind of logic.

作业不需要太多的事件设置,因为您只需要一个类,而不需要事件和侦听器.

Jobs require less set up to events as you only need a single class, rather than events and listeners.

要延迟您的工作,请使用以下语法,其中SendReminderEmail是您的工作.延迟功能中的参数是您希望延迟该过程的秒数.

To delay your job use the following syntax, where SendReminderEmail is your job. The parameter in the delay function is the number of seconds you wish to delay the process.

$job = (new SendReminderEmail($user))->delay(60);

https://laravel.com/docs/5.1/queues#delayed-jobs

这篇关于一定时间后在Laravel触发事件或听众的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆