Home> PHP Framework> Laravel> body text

Detailed explanation of how to use laravel's task scheduling (scheduled execution of tasks)

藏色散人
Release: 2021-01-06 09:44:20
forward
2479 people have browsed it

The following columnLaravel Tutorialwill introduce you to task scheduling (regular execution of tasks) using laravel. I hope it will be helpful to friends in need!

Detailed explanation of how to use laravel's task scheduling (scheduled execution of tasks)

There is a very powerful function in laravel. You only need to add a cron entry on the server to execute all laravel tasks regularly.

Now we have the following data table:

I want the value of the cron field in the cron table to increase by 1 every minute, then I need the following steps:

1.Write laravel code inApp\Console\Kernel.php

protected function schedule(Schedule $schedule) { $schedule->call(function () { DB::table('cron')->increment('cron'); })->everyMinute(); }
Copy after login

2. In the/ of the service Add code to the var/spool/cron/rootfile

Note: It is best to use the vim editor to edit the file here. If you use winscp to edit the file, something will appear. Task execution issues.

Using vim tutorial link: http://www.cnblogs.com/zzdylan/p/5941706.html

Enter

crontab -e
Copy after login

on the command line and add the following code

* * * * * /usr/local/php/bin/php /data/wwwroot/test/artisan schedule:run 1>> /dev/null 2>&1
Copy after login

Enter

crontab -u root -l
Copy after login

on the command line. There is no need to restart the cron service, because the system will read/var/spool/cron every minute.Files in the directory.

If you find that it still cannot be executed according to the following configuration, you can use the following methods to troubleshoot the problem:

Check whether the command uses an absolute path, such as here/usr/local/php/bin/phpinstead ofphp, use/data/wwwroot/test/artisaninstead ofartisan.

If the absolute path is still not executed, then directly enter/usr/local/php/bin/php /data/wwwroot/test/artisan schedule:run 1>> on the command line ; /dev/null 2>&1and see if it is executed. If it is not executed, it is a problem with the laravel code. If it is executed, it means that it is an environment variable problem. Check the path. If you don’t know where php is, enterwhich phpon the command line, and you will be prompted where php is installed.

For more programming-related knowledge, please visit:Programming Teaching! !

The above is the detailed content of Detailed explanation of how to use laravel's task scheduling (scheduled execution of tasks). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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!