首頁  >  問答  >  主體

指定時間時Cron作業無法正常運作

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

P粉347804896P粉347804896178 天前366

全部回覆(2)我來回復

  • P粉057869348

    P粉0578693482024-03-29 14:22:49

    取代您的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 一定會工作

    回覆
    0
  • P粉232793765

    P粉2327937652024-03-29 13:40:39

    你可以這樣執行 cron:

    protected function schedule(Schedule $schedule)
    {
         $schedule->command('backup:run')->dailyAt('03:51');
    }

    回覆
    0
  • 取消回覆