PHP-如何在运行另一行代码10分钟后运行一行代码 [英] PHP - How to Run a line of code after 10 minutes of running another line of code

查看:52
本文介绍了PHP-如何在运行另一行代码10分钟后运行一行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的应用程序在发送另一封电子邮件10分钟后发送一封电子邮件.

I want my application will send a email after 10 minutes of sending another email.

在我的应用程序中

  • 用户完成付款注册
  • 应用程序向用户发送付款确认电子邮件

现在我要

  • 再发送一封电子邮件,付款确认后10分钟发送一封带有欢迎提示的电子邮件

下面是用于用户设置的功能.

Below is the function where for user setup .

   public function finishUserSetup($Sub){

    if($Sub == 0){
        $subscription = SubscriptionPlans::where('identifier', '=', "Monthly")->first();
        $expiry = date('Y-m-d', strtotime('+' . $subscription->months . ' months'));
        $sub_period = "monthly";
    
    } else{
        $subscription = SubscriptionPlans::where('identifier', '=', "Annually")->first();
        $expiry = date('Y-m-d', strtotime('+' . $subscription->months . ' months'));
        $sub_period = "annually";
    }

    $this->expiry_date = $expiry;
    $this->user_type = "SUB";
    $this->subscription_period = $sub_period;
    $this->update();

    $replaceArray = array(
        'fullname' => $this->forename . " " . $this->surname,
        'subscriptionName' => $subscription->name,
        );
    EmailTemplate::findAndSendTemplate("paymentconfirm", $this->email, $this->forename . " " . $this->surname, $replaceArray);

  }

在上述功能中,最后一行代码是向用户发送付款确认电子邮件的代码,

In the above function the last line of code is the one which sends a payment confirmation email to the user which is

EmailTemplate::findAndSendTemplate("paymentconfirm", $this->email, $this->forename . " " . $this->surname, $replaceArray);

我想在上一行代码之后10分钟执行以下代码行

I want to execute the following line of code 10 minutes after the above one

EmailTemplate::findAndSendTemplate("WelcomeTips", $this->email, $this->forename . " " . $this->surname, $replaceArray);

如何在10分钟后运行上面的代码行

How to run the above line of code after 10 minutes

推荐答案

首先在laravel项目中设置队列配置.然后用

First set up the queue configuration in your laravel project . then create a job with

 php artisan make:job YourNameJob

将电子邮件发送过程转移到 YoutNameJob 中,最后在finishUserSetup方法中分两次发送 YoutNameJob

Transfer the email sending process into YoutNameJob , and finally dispatch YoutNameJob twice in the finishUserSetup method, like this

 public function finishUserSetup($Sub){

   .
   .
   .

    YoutNameJob::dispatch([arguments])->delay(now());

    YoutNameJob::dispatch([arguments])->delay(now()->addMinutes(10));

  }

这篇关于PHP-如何在运行另一行代码10分钟后运行一行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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