search
HomePHP FrameworkThinkPHPDetailed explanation of the implementation steps of thinkphp5.1/5.0 scheduled tasks

The tutorial column of thinkphp below will give you a detailed explanation of the steps to implement thinkphp5.1/5.0 scheduled tasks. I hope it will be helpful to friends in need!

What I mainly do is the function of sending text messages to employees on their birthdays. I run the script once a day.

The first step:

a.App Create a command folder under /module/

b. I created it in the admin module and created a SendMessage.php file under the command folder (the specific name is determined by yourself according to your needs)

c. Copy the following code to SendMessage.php

<?php
 namespace app\admin\command;
  
 use think\console\Command;
 use think\console\Input;
 use think\console\Output;
 use think\Db;
 use think\Log;
  
 class SendMessage extends Command
 {
     protected function configure(){
         $this->setName(&#39;SendMessage&#39;)->setDescription("计划任务 SendMessage");
     }
  
     //调用SendMessage 这个类时,会自动运行execute方法
     protected function execute(Input $input, Output $output){
         $output->writeln(&#39;Date Crontab job start...&#39;);
         /*** 这里写计划任务列表集 START ***/
  
         $this->birthday();//发短信
  
         /*** 这里写计划任务列表集 END ***/
         $output->writeln(&#39;Date Crontab job end...&#39;);
     }
  
     //获取当天生日的员工 发短信
     public function birthday()
     {
         echo &#39;这里写你要实现的逻辑代码&#39;;
     }
 }

Step 2: Add

return [&#39;app\admin\command\SendMessage&#39;];

in APP/command.php

Step 3: Set up crontab scheduled tasks

  1. ##crontab -l //Scheduled task list

  2. crontab -e //Edit to add

  3. crontab -r //Delete

In order to facilitate testing, you can first set it to execute once every minute and record the log /www/wwwroot/tool/runtime/message/2019.log

  1. */1 * * * * php /www/wwwroot/tool/think SendMessage>>/www/wwwroot/tool/runtime/message/2019.log 2>&1

  2. ##//Monitor whether your script is normal

  3. ##tail -f /www/wwwroot/tool/ runtime/message/2019.log

The above is the detailed content of Detailed explanation of the implementation steps of thinkphp5.1/5.0 scheduled tasks. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor