指定时间时,Cron 作业不工作
Cron job is not working when specify time
我有一个 Laravel 项目 v8,我已经为数据库备份创建了一个 cron 作业
它每分钟都在工作,但是当我指定每天的时间时它不工作。
项目时区是 'Asia/Kolkata',我的 GoDaddy 共享服务器时区是 UTC。
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();
$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
<?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 以及您要执行的时间
检查 cpanel 中的给定时间,cron 肯定会工作
你可以 运行 cron 像这样:
protected function schedule(Schedule $schedule)
{
$schedule->command('backup:run')->dailyAt('03:51');
}
我有一个 Laravel 项目 v8,我已经为数据库备份创建了一个 cron 作业
它每分钟都在工作,但是当我指定每天的时间时它不工作。
项目时区是 'Asia/Kolkata',我的 GoDaddy 共享服务器时区是 UTC。
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();
$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
<?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 以及您要执行的时间
检查 cpanel 中的给定时间,cron 肯定会工作
你可以 运行 cron 像这样:
protected function schedule(Schedule $schedule)
{
$schedule->command('backup:run')->dailyAt('03:51');
}