


Detailed 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('SendMessage')->setDescription("计划任务 SendMessage"); } //调用SendMessage 这个类时,会自动运行execute方法 protected function execute(Input $input, Output $output){ $output->writeln('Date Crontab job start...'); /*** 这里写计划任务列表集 START ***/ $this->birthday();//发短信 /*** 这里写计划任务列表集 END ***/ $output->writeln('Date Crontab job end...'); } //获取当天生日的员工 发短信 public function birthday() { echo '这里写你要实现的逻辑代码'; } }
Step 2: Add
return ['app\admin\command\SendMessage'];
Step 3: Set up crontab scheduled tasks
##crontab -l //Scheduled task list
crontab -e //Edit to add
crontab -r //Delete
*/1 * * * * php /www/wwwroot/tool/think SendMessage>>/www/wwwroot/tool/runtime/message/2019.log 2>&1
- ##//Monitor whether your script is normal
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor
