运行 在事件发生前几个小时运行
Run function few hours before event occurs
我有一个问题。我正在学习 cakephp 3,我想执行以下操作:
用户输入日期和时间(这被保存到 mysql 作为日期时间格式)并且系统需要在他输入的这个日期时间之前几个小时发送电子邮件(例如,1 小时之前)
但是,我想在没有 cronjob 的情况下执行此操作。
因此用户输入 2019-05-12 12:00,我想立即安排任务在 2019-05-12 11:00 发送电子邮件。
这可能吗,是的,你能给我一些指示吗? cakephp tasks我也查了,不过好像还没有看到全貌
创建Shell
bin/cake bake shell CronJobs
打开创建的shell并创建发送邮件的方法,例如:
public function sendEmal()
{
}
在此方法中,将您的代码添加到 select 数据和 Mailer 以发送邮件。
现在在您的 cron 选项卡中设置任务并指向此 shell 脚本,例如
* 1 * * * bin/cake CronJob sendEmail
请阅读:
- https://book.cakephp.org/3.0/en/console-and-shells/shells.html
- https://book.cakephp.org/3.0/en/console-and-shells/cron-jobs.html
- https://book.cakephp.org/3.0/en/core-libraries/email.html
更新:
However, I want to do this without cronjob.
其他方法是实现一些队列系统。
阅读here了解更多信息
我有一个问题。我正在学习 cakephp 3,我想执行以下操作: 用户输入日期和时间(这被保存到 mysql 作为日期时间格式)并且系统需要在他输入的这个日期时间之前几个小时发送电子邮件(例如,1 小时之前)
但是,我想在没有 cronjob 的情况下执行此操作。
因此用户输入 2019-05-12 12:00,我想立即安排任务在 2019-05-12 11:00 发送电子邮件。
这可能吗,是的,你能给我一些指示吗? cakephp tasks我也查了,不过好像还没有看到全貌
创建Shell
bin/cake bake shell CronJobs
打开创建的shell并创建发送邮件的方法,例如:
public function sendEmal()
{
}
在此方法中,将您的代码添加到 select 数据和 Mailer 以发送邮件。
现在在您的 cron 选项卡中设置任务并指向此 shell 脚本,例如
* 1 * * * bin/cake CronJob sendEmail
请阅读:
- https://book.cakephp.org/3.0/en/console-and-shells/shells.html
- https://book.cakephp.org/3.0/en/console-and-shells/cron-jobs.html
- https://book.cakephp.org/3.0/en/core-libraries/email.html
更新:
However, I want to do this without cronjob.
其他方法是实现一些队列系统。
阅读here了解更多信息