Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

496
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!