我有一個(gè) Laravel 項(xiàng)目 v8,并且我已經(jīng)創(chuàng)建了一個(gè)用于數(shù)據(jù)庫備份的 cron 作業(yè)
它每分鐘都在工作,但當(dāng)我指定每天的時(shí)間時(shí),它就不起作用。
項(xiàng)目時(shí)區(qū)是“亞洲/加爾各答”,我的 GoDaddy 共享服務(wù)器時(shí)區(qū)是 UTC。
內(nèi)核.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。
替換您的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 上設(shè)置 cronjob 以及您要執(zhí)行的時(shí)間
檢查 cpanel 中的給定時(shí)間,cron 一定會(huì)工作
你可以像這樣運(yùn)行 cron:
protected function schedule(Schedule $schedule) { $schedule->command('backup:run')->dailyAt('03:51'); }