Answer the question
In order to leave comments, you need to log in
Cron and Laravel, where are the pitfalls?
There is a small project in which it is necessary to make tasks that are customizable in time.
I'm trying to use laravel, which has several options for the development of events in the dock, such as:
Commands (required for them):
<?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\RemovalPositions'
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command("site:removalPositions")->everyMinute();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class RemovalPositions extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'site:removalPositions';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
//$this->site = $site;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//$name = $this->site->name;
DB::table("TEST")->insert(["sdf" =>"222323"]);
}
}
$schedule->call('[email protected]')->everyMinute();
$schedule->call(function () {
DB::table("TEST")->insert(["sdf" => "12312313123"]);
})->everyMinute();
php artisan schedule:run
No scheduled commands are ready to run.
Answer the question
In order to leave comments, you need to log in
Because cron runs on time.
The php artisan schedule:run command itself is run by cron every minute.
And performs, respectively, the tasks that should be at this time.
In order to manually start it is necessary to start exactly in time at zero second in this case.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question