laravel5.4计划任务教程,PHP计划任务在linxu里运行,larave5.4计划任务在linux上运行
PHP代码写在 app/Console/Kerenl文件里 /** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { $schedule->call(function () { //这里是你的PHP业务代码 })->twiceDaily(12, 23);//执行时间 }
#/var/www/html/myweb/ 这个是你项目的根目录 cd /var/www/html/myweb/ PHP artisan schedule:run
3.在linux加上crontab
cd /etc vim crontab //文件如下 SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # For details see man 4 crontabs # Example of job deFinition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed */1 * * * * root /var/www/html/myweb/map.sh
这个就是你需要执行的sh文件地址根据你自己的项目来写 */1 * * * * root /var/www/html/myweb/map.sh
4.重新载入
/sbin/service crond reload //重新载入配置
相关命令
/sbin/service crond start //启动服务 /sbin/service crond stop //关闭服务 /sbin/service crond restart //重启服务 /sbin/service crond reload //重新载入配置
laravel5.4计划任务时间
方法 | 描述 |
---|---|
->cron('* * * * *'); |
在自定义Cron调度上运行任务 |
每个星期三运行任务 |
基于特定时间段运行任务 |