Preface
My friends and I wrote a small system for micro-classroom using thinkphp5.1. Implement a daily class reminder and data initialization function. The method is now written, but each execution requires a manual click on the administrator interface. It feels very troublesome. How can I make it automatically execute at a scheduled time every day?
Predecessor methods
Search tp5.1 timed tasks or planned tasks on Google. There will be many blogs, but most of them are scripts under Linux. I just Install the Linux system. I am not very familiar with Linux, so I will first use the Windows system.
Idea
The implementation ideas in windows environment and Linux environment are the same.
1. Now write the implementation method into a trigger, and you can click to jump to implement it.
2. Write a script to automatically open a web page.
3. Use the scheduled task that comes with Windows to automatically execute this script at regular intervals.
Implementation
1. We now write a test trigger under the login controller
public function test() // 自动执行测试 { echo "这是一个定时任务的测试"; }
The trigger effect is as follows
@echo off start iexplore.exe http://127.0.0.1/index/login/test Ping -n 5 127.1>nul Taskkill /f /im iexplore.exe echo success >> test.txt
start iexplore.exe http://127.0.0.1/index/login/test represents the URL to open the browser The specific URL is written at the end,
Ping -n 5 127.1>nul means waiting for 5 seconds,
Taskkill /f /im iexplore.exe means closing the browser,
echo success > ;> test.txt indicates a successful return to Notepad. Since writing comments will cause an error in the code, write a code comment here.
Click on the test .bat file
The code is as follows
curl -X POST -H "Content-type: application/json" ^ --data "{\"text\": {\"content\": \"每日初始完成\"}, \"msgtype\": \"text\"}" ^ https://oapi.dingtalk.com/robot/send?access_token=23dc64f0dee37b5ee3b1ac472b2c84d837afa15b2a884b87b32f898998408a36
Trigger: Every day
Start: //Choose a time you like
Operation: Start the program->Select this script
Complete