Laravel-Task Scheduling
Tags (separated by spaces): PHP
Introduction
Cron is a very useful tool in UNIX, Solaris, and Linux. The Cron script enables scheduled tasks to run automatically on the system background on a regular basis. This scheduled task is named cron jobs in UNIX, Solaris, and Linux. Crontab is a script file used to record the cron running at a specific time. Each row of the crontab file complies with the specific format:
?
We can add or edit cron entries through crontab-E on the server, and view the existing cron entries through crontab-L. For more information about cron principles and usage, Baidu or Google.
In the past, developers had to write a Cron entry for each task to be scheduled, which was a headache. Your task scheduling is not controlled by source code. You must log on to the server using SSH and add these cron entries.
The laravel command scheduler allows you to stream and elegantly define command Scheduling in laravel, and only one cron entry is required on the server. Task Scheduling is defined in the schedule method of the APP/console/kernel. php file. This method contains an example.
Enable Scheduler
Below are the only cron entries you need to add to the server. If you do not know how to add cron entries to the server, you can consider using services such as laravel forge to manage cron entries:
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
The cron will call the laravel command scheduler once every minute. When the schedule: Run Command is executed, laravel evaluates your scheduling task and runs the expired task.
1. Add cron to the server
In crontab-E mode, add the following content: *****/usr/local/PHP/bin/PHP/home/wwwroot/web.laravel.cn/artisan schedule: run>/dev/null 2> & 1 ***** time/usr/local/PHP/bin/PHP: your own PHP Environment [whereis PHP]/home/wwwroot/web.laravel.cn/artisan: artsian directory schedule: Run>/dev/null 2> & 1: fixed syntax
2. Create a file
PHP artisan make: Console loginfo [custom file name] if an error is reported, run php artisan make: Command
The file is located at: app \ console \ commands \ loginfo. php
3. Complete file registration
Write your function in the handle Method
In app \ console \ kernel. php
4. Run
PHP artisan schedule: Run
Enable proc_open () function
Enable proc_get_status () function
Execution successful
Record log results
Proc_open () proc_get_status () modify the phpini file and remove the two functions in disabled.
Laravel-Task Scheduling