Home >Backend Development >PHP Tutorial >Laravel task scheduling

Laravel task scheduling

WBOY
WBOYOriginal
2016-07-29 09:14:491347browse

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

          • root php /home/vagrant/Code/artisan schedule:run

      Note: Laravel documentation has

          • php / path/to/artisan schedule:run 1>> /dev/null 2>&1

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn