Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RileyGWeb's avatar

Laravel Scheduler Running Tasks Twice Every Minute

The Laravel Scheduler where it seems to be running my scheduled tasks twice every minute, and I can't figure out why.

I'm hosting on Forge, this is the cron job setup I have (runs once per minute):

* * * * * cd /path-to-my-laravel-project && php artisan schedule:run >> /path-to-my-laravel-project/storage/logs/cron.log 2>&1

Kernel.php:

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Log;

class Kernel extends ConsoleKernel
{
    protected function schedule(Schedule $schedule): void
    {
        Log::info('Running schedule.');
        $schedule->command('refresh:pollingdata')->everyMinute();
        $schedule->command('check:pollingstatus')->everyFiveMinutes();
    }

    protected function commands(): void
    {
        $this->load(__DIR__.'/Commands');
        require base_path('routes/console.php');
    }
}

In my logs, I see the "Running schedule." message twice every minute, back-to-back, which indicates that the scheduler is being triggered twice.

[2023-09-25 22:43:00] local.INFO: Running schedule.  
[2023-09-25 22:43:00] local.INFO: Running schedule.  
[2023-09-25 22:43:01] local.INFO: [redacted, just some info about the polling process]
[2023-09-25 22:43:01] local.INFO: --------------------------  
[2023-09-25 22:43:01] local.INFO: Finishing data refresh from command. Time: 2023-09-25 17:43:01  
[2023-09-25 22:44:00] local.INFO: Running schedule.  
[2023-09-25 22:44:01] local.INFO: Running schedule.  
[2023-09-25 22:44:01] local.INFO: [redacted, just some info about the polling process]
[2023-09-25 22:44:01] local.INFO: --------------------------  
[2023-09-25 22:44:01] local.INFO: Finishing data refresh from command. Time: 2023-09-25 17:44:01  

What I've Tried:

  1. Checked the cron job setup to ensure it's running once per minute.
  2. Checked for overlapping tasks and ensured tasks complete within their scheduled intervals.
  3. Cleared Laravel's cache.
  4. Checked for any external triggers or scripts that might be running the scheduler.

Any ideas?

0 likes
7 replies
LaryAI's avatar
Level 58

It seems like the Laravel scheduler is running the tasks twice every minute. Here are a few things you can try to resolve this issue:

  1. Check for overlapping tasks: Make sure that there are no other tasks or processes that are triggering the scheduler. Double-check your codebase for any other instances where the scheduler might be called.

  2. Verify the cron job setup: Ensure that the cron job is set up correctly to run once per minute. You can do this by running the following command in your terminal:

    crontab -l
    

    This will display the current cron jobs. Verify that the Laravel scheduler command is set to run once per minute.

  3. Clear Laravel's cache: Sometimes, cached data can cause unexpected behavior. Try clearing Laravel's cache by running the following command:

    php artisan cache:clear
    
  4. Check for external triggers: Look for any external triggers or scripts that might be running the scheduler. Check your server logs or any other processes that might be interacting with the scheduler.

If none of these solutions work, you can try adding a lock to prevent the scheduler from running multiple times simultaneously. You can do this by modifying your Kernel.php file as follows:

use Illuminate\Console\Scheduling\Mutex;

class Kernel extends ConsoleKernel
{
    protected function schedule(Schedule $schedule): void
    {
        $mutex = new Mutex();

        if ($mutex->create()) {
            $schedule->command('refresh:pollingdata')->everyMinute();
            $schedule->command('check:pollingstatus')->everyFiveMinutes();

            $mutex->release();
        }
    }
}

This will ensure that the scheduler only runs once at a time by acquiring and releasing a lock.

I hope this helps! Let me know if you have any further questions.

krisi_gjika's avatar
Level 14

"In my logs, I see the "Running schedule." message twice every minute, back-to-back, which indicates that the scheduler is being triggered twice." - no? it only means the schedule method is being called twice. why is "Finishing data refresh from command" only once?

Try something like:

$schedule->call(function () {
  \Log::info('Running schedule.');
})->everyMinute();
1 like
RileyGWeb's avatar

@krisi_gjika This ended up being correct. It appears to run once per command, so with two commands total it makes sense. In hindsight should have been obvious as each command was only being executed once the whole time. Thanks!

1 like
Snapey's avatar

I agree with @krisi_gjika .

    protected function schedule(Schedule $schedule): void
    {
        Log::info('Running schedule.');
        $schedule->command('refresh:pollingdata')->everyMinute();
        $schedule->command('check:pollingstatus')->everyFiveMinutes();
    }

only shows that the schedule is being evaluated twice.

If it were triggering double the jobs then you would see the refresh:pollingdata called twice.

1 like
rodrigo.pedra's avatar

@coaster132 Did you add your CRON entry manually?

Run these commands to check if you have a duplicate CRON entry for user, for root, and the system's crontab files (forge defaults to using that):

crontab -l
sudo crontab -l
cat /etc/crontab

Run those as the regular forge user when logging on SSH

The entries shown on Forge server's dashboard are those added to the system's crontab file, the user's one aren't shown there.

If I am not mistaken, Forge creates a CRON entry automatically for every site you add to a server, so always check Forge's dashboard before adding any automatically.

Please or to participate in this conversation.