Home >Backend Development >PHP Tutorial >Laravel task scheduling
Call laravel commands or methods through server scheduled tasks
1. What to do to create a scheduled task under appConsoleCommands
Create command: php artisan make:console test
$signature = "testCommand"; The signature here, in It is also used in the task commands in kernel.php;
2. Call in Kernel.php
protected $commands = [
'AppConsoleCommandstest', #A collection of artisans to be called in the application
];
<code>$schedule->command('testCommand')->everyMinute(); #这里的testCommand与app\Console\Commands中的签名要相同 </code>
Note: You can also use $schedule->command('testCommand')->cron('* * * * *'); to set the time
3. You also need to configure the /etc/crontab file
Note: Laravel documentation has
The path here is the path of the project rather than the file path!!!
Tasks under Linux Scheduling is divided into system and user task scheduling:
a.crontab -e is user-defined and will be written to the /var/spool/cron directory and claims a file consistent with the user name. The content of the file is Edited scheduled script
[You can enter /var/spool/cron to view the user directory]
Work that users need to perform regularly, such as user data backup, scheduled email reminders, etc.
b.vim /etc/crontab belongs to the system level, and the system performs tasks periodically, such as writing cached data to the hard disk, log cleaning, etc.
The above has introduced Laravel task scheduling, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.