Home> PHP Framework> Laravel> body text

PHP Laravel scheduled task Schedule [dry information]

藏色散人
Release: 2020-06-23 13:43:30
forward
5207 people have browsed it

The following is the tutorial column ofLaravelto introduce PHP Laravel scheduled task Schedule. I hope it will be helpful to friends who need it!

PHP Laravel scheduled task Schedule [dry information]

Premise: The method in this article is to use Linux's crontab scheduled task to assist in implementing Laravel scheduling (the same is true for Mac).

1. First add the Crontab scheduled task. Here is just a brief introduction.

Use the command crontab -e to add the following content

* * * * * /usr/local/bin/php /usr/local/var/www/projectName/artisan schedule:run >> /dev/null 2>&1
Copy after login

As shown:

PHP Laravel scheduled task Schedule [dry information]

The above command Crontab will adjust every minute Laravel's schedule command, and then Laravel determines the execution task.

Note: Pay attention to the directories of php and artisan, which php can view the php directory

***** Your command

In addition, the above The five * in front of the command represent minutes, hours, days, months, and weeks respectively.

Minute: an integer from 0-59, the default * and */1 represent 1 minute.

Hour: an integer from 0 to 23.

Day: an integer from 1 to 31.

Month: an integer from 1 to 12.

Weekday: an integer from 0 to 7, both 0 and 7 represent Sunday.

crontab -l can list the current scheduled tasks.

2. Add Laravel scheduling task.

1. Define your scheduling task in the App\Console\Kernel class:

call(function () { // Log::info('任务调度'); // })->everyMinute(); //方法二: $schedule->command('test')->everyMinute(); } }
Copy after login

The above gives two examples of implementation methods. The first method is to use closures, and the second method is Implemented using Artisan commands.

There are many scheduling times:

->cron(‘* * * * *’); 在自定义Cron调度上运行任务 ->everyMinute(); 每分钟运行一次任务 ->everyFiveMinutes(); 每五分钟运行一次任务 ->everyTenMinutes(); 每十分钟运行一次任务 ->everyThirtyMinutes(); 每三十分钟运行一次任务 ->hourly(); 每小时运行一次任务 ->daily(); 每天凌晨零点运行任务 ->dailyAt(‘13:00’); 每天13:00运行任务 ->twiceDaily(1, 13); 每天1:00 & 13:00运行任务 ->weekly(); 每周运行一次任务 ->monthly(); 每月运行一次任务
Copy after login

There are additional methods, please refer to: http://laravelacademy.org/post/235.html

Continue the operation of method two:

Third, define the method of Artisan command:


        
Copy after login

Okay, the above can execute the scheduled task , there is a little trick. If the above tasks are not executed, you can use the command php artisan list to print out some error messages.

For more laravel related technical articles, please visit thelaravelcolumn!

The above is the detailed content of PHP Laravel scheduled task Schedule [dry information]. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!