Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

498
Visualizações
Laravel Command Schedule Not Working Properly

I'm building a project with Laravel 7.28 on localhost. I need to update a PDF every hour. For the beginning I created a command:

<?php

namespace App\Console\Commands;

use App\Event;
use Illuminate\Console\Command;

class PDF extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'pdf:update';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'All Country PDFs updated';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {

        $event = new Event();
        $event->user_id = 1;
        $event->save();

        echo 'done';
    }
}

It just insert a record into events table and works fine. Then I edited the Kernel.php under App\Console directory.

<?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 = [
        Commands\PDF::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param \Illuminate\Console\Scheduling\Schedule $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('pdf:update')->everyMinute();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__ . '/Commands');

        require base_path('routes/console.php');
    }
}

Finally, I run php artisan schedule:run. I was expecting that the command runs every minute but it just runs once. is this a problem on localhost or did I do something wrong?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

The php artisan schedule:run just runs once by its definition:

The schedule:run Artisan command will evaluate all of your scheduled tasks and determine if they need to run based on the server's current time.

If you want to do it every minute you should use a scheduled process control system like supervisor or crontab or etc. (more info here)

In case if you are using laravel 8.x and running on a development/local server you can use the following command and it will work for you:

php artisan schedule:work
over 4 years ago · Santiago Trujillo Relatório

0

For Laravel 7 you can also use below command to run in your local

while true; do php artisan schedule:run; sleep 60; done
over 4 years ago · Santiago Trujillo Relatório

0

On windows localhost

  1. First of all set your desired schedule job on the run method inside App\Console\Kernel More information on the Laravel website page here

  2. Secondly on the command line run the following command

php artisan schedule:work

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda