我有一个 Laravel 项目 v8,并且我已经创建了一个用于数据库备份的 cron 作业
它每分钟都在工作,但当我指定每天的时间时,它就不起作用。
项目时区是“亚洲/加尔各答”,我的 GoDaddy 共享服务器时区是 UTC。
内核.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('backup:clean')->everyMinute();
$schedule->command('backup:run')->cron('51 3 * * *');
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
我在 Cpanel 上的 cronjob。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
替换您的kernel.php
command('backup:clean')->everyMinute(); } /** * Register the commands for the application. * * @return void */ protected function commands() { $this->load(__DIR__.'/Commands'); require base_path('routes/console.php'); } }在此之后,在 Cpanel 上设置 cronjob 以及您要执行的时间
检查 cpanel 中的给定时间,cron 一定会工作
你可以像这样运行 cron:
protected function schedule(Schedule $schedule) { $schedule->command('backup:run')->dailyAt('03:51'); }