Laravel 任務計劃程式在 Windows XAMPP 服務器中無法正常作業。我制作了資料庫自動備份腳本源。備份資料庫作業正常,但 Laravel 調度程式在 Windows 服務器中無法正常作業
app/Console/Commands/DatabaseBackUp.php使用php artisan make:command DatabaseBackUp命令創建的檔案
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Carbon\Carbon;
class DatabaseBackUp extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'database:backup';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$filename = "backup-" . Carbon::now()->format('Y-m-d') . ".sql";
$command = "". env('DUMP_COMMAND_PATH') ." --user=" . env('DB_USERNAME') ." --password=" . env('DB_PASSWORD') . " --host=" . env('DB_HOST') . " " . env('DB_DATABASE') . " > " . storage_path() . "/app/backup/" . $filename;
$returnVar = NULL;
$output = NULL;
exec($command, $output, $returnVar);
dd("Database backup Successfully Done - $filename Time:- ".Carbon::now());
}
}
?>
app/Console/Kernel.php檔案
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
'App\Console\Commands\DatabaseBackUp'
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
$schedule->command('database:backup')
->daily()
->appendOutputTo(storage_path('logs/db-backups.log'));
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
現在,當我php artisan database:backup手動點擊命令時,它會創建資料庫備份...
但根據
- 根據需要填寫輸入欄位。有關更多詳細資訊,請參閱此處如何填寫任務計劃程式中的欄位
對于Windows(技巧 2)
If you wants to prevent command line won’t popup every single minute when scheduler runs your task. then you can use 2nd trick
press Windows R, write Taskschd.msc and press enter & open Task Scheduler
fill the fields. but In the tab 'Actions' click on 'New', in the field 'Action' select 'Start a program'
then in settings section fill
C:\xampp\php\php.exein Program/Script input field &C:\xampp\htdocs\microtechcoupon\artisan schedule:runin Add arguments (optional) field & then save it
credit of 2nd Trick in windows :- https://quantizd.com/how-to-use-laravel-task-scheduler-on-windows-10/
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/357877.html
標籤:视窗 xampp laravel-8 laravel 调度器
