admin管理员组文章数量:1639934
crontab -e 定时任务
1、打开Xshell,连接上服务器
2、crontab -e //进入编辑器
3、按“a”,进入编辑
4、新增一行:
* * * * * /usr/localphp/bin/php 项目结对路径/artisan schedule:run >> /dev/null 2>&1
* * * * *
分 时 日 月 星期
5、按“ESC”,:wq //保存并退出
6、crontab -l //查看刚才执行的命令
7、重启crontab
/bin/systemctl restart crond.service
8、运行定时任务
cd 项目绝对路径 //进入项目根目录
php artisan schedule:run //运行定时任务
查看命令:php artisan list
项目内定时任务部署
app/Console/Kernel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->call(
'App\Http\Admin\Task\TaskController@timingTask'
)->daily(); //每天凌晨零点运行任务
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
->cron('* * * * *'); //在自定义Cron调度上运行任务
->everyMinute(); //每分钟运行一次任务
->everyFiveMinutes(); //每五分钟运行一次任务
->everyTenMinutes(); //每十分钟运行一次任务
->everyFifteenMinutes(); //每十五分钟运行一次任务
->everyThirtyMinutes(); //每三十分钟运行一次任务
->hourly(); //每小时运行一次任务
->hourlyAt(17); //每小时第17分钟运行一次任务
->daily(); //每天凌晨零点运行一次任务
->dailyAt('13:00'); //每天13:00运行一次任务
->twiceDaily(1,13); //每天1:00 & 13:00运行任务
->weekly(); //每周运行一次任务
->monthly(); //每月运行一次任务
->monthlyOn('4', '15:00'); //每月4号15:00运行一次任务
->quarterly(); //每个季度运行一次任务
->yearly(); //每年运行一次任务
->timezone('America/New_York'); //设置时区
版权声明:本文标题:laravel schedule 定时任务 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1725780070a1042156.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论