我有一個 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。

uj5u.com熱心網友回復:
你可以像這樣運行 cron:
protected function schedule(Schedule $schedule)
{
$schedule->command('backup:run')->dailyAt('03:51');
}
uj5u.com熱心網友回復:
替換你的kernel.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();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
然后在 Cpanel 上設定 cronjob 以及您要執行的時間
檢查 cron 在 cpanel 中的給定時間是否可以正常作業
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/462679.html
