为什么它不能每 5 分钟循环一次函数? (cronjob, 任务调度laravel)
Why it cant loop the function every 5 minutes? (cronjob, task scheduling laravel)
我正在尝试设置一个可以 运行 每五分钟一次的计划任务,但它只工作了 1 次,在前五分钟之后,其他五分钟就不能正常执行该功能。
//depresiasicounter.php
protected $signature = 'updates:depresiasicounter';
public function handle()
{
$aktivatb = Aktivatb::where('id','1')->first();
$aktivatb->nilai= $aktivatb->nilai-$aktivatb->depresiasi;
$aktivatb->total_depresiasi = $aktivatb->total_depresiasi+$aktivatb->depresiasi;
$aktivatb->save();
}
//kernel.php
protected $commands = [
Commands\DepresiasiCounter::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->commands('updates:depresiasicounter')->everyFiveMinutes();
}
我预计$aktivatb->nilai的值可以一直工作到0,但是只工作了1次
您需要设置 cron 以便它可以每分钟 运行 php artisan schedule:run 命令,因此您需要将以下 Cron 条目添加到您的服务器。
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
此 Cron 每分钟都会调用 Laravel 命令调度程序。然后,Laravel 评估您的计划任务和 运行 到期的任务。
使用调度程序时,您只需将以下 Cron 条目添加到您的服务器即可。
一个计划任务基本上就是系统在运行宁一个命令
php /project-path/artisan schedule:run
每个给定的时间。
在Linux环境中,人们使用cron通过创建crontab
来处理这个问题
* * * * * php /project-path/artisan schedule:run
命令前面的那些星号表示间隔
命令。
在Windows环境下,可以参考以下answer.
或者您可以设置一个虚拟机和 运行 机器内部的 cron 作业。
我正在尝试设置一个可以 运行 每五分钟一次的计划任务,但它只工作了 1 次,在前五分钟之后,其他五分钟就不能正常执行该功能。
//depresiasicounter.php
protected $signature = 'updates:depresiasicounter';
public function handle()
{
$aktivatb = Aktivatb::where('id','1')->first();
$aktivatb->nilai= $aktivatb->nilai-$aktivatb->depresiasi;
$aktivatb->total_depresiasi = $aktivatb->total_depresiasi+$aktivatb->depresiasi;
$aktivatb->save();
}
//kernel.php
protected $commands = [
Commands\DepresiasiCounter::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->commands('updates:depresiasicounter')->everyFiveMinutes();
}
我预计$aktivatb->nilai的值可以一直工作到0,但是只工作了1次
您需要设置 cron 以便它可以每分钟 运行 php artisan schedule:run 命令,因此您需要将以下 Cron 条目添加到您的服务器。
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
此 Cron 每分钟都会调用 Laravel 命令调度程序。然后,Laravel 评估您的计划任务和 运行 到期的任务。
使用调度程序时,您只需将以下 Cron 条目添加到您的服务器即可。
一个计划任务基本上就是系统在运行宁一个命令
php /project-path/artisan schedule:run
每个给定的时间。
在Linux环境中,人们使用cron通过创建crontab
来处理这个问题* * * * * php /project-path/artisan schedule:run
命令前面的那些星号表示间隔 命令。
在Windows环境下,可以参考以下answer.
或者您可以设置一个虚拟机和 运行 机器内部的 cron 作业。