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

hameti's avatar

Laravel scheduler does not respect the time set

I have a helper containing the function removeOldMessages() and a job scheduled for 2 am everyday as below in the Kernel.php

$schedule->call(removeOldMessages())->cron('0 2 * * *')->name('removeoldmessages')->withoutOverlapping()->onOneServer();

The function removeOldMessages() writes to the log so I can see the results. The issue is that the job runs every time the cronjob triggers that is every half an hour (Im on shared hosting). That is the scheduler does not respect the timing. Am I doing something wrong here?

Here is what I set into the cronjob in Cpanel

cd xxxx/laravel && /usr/local/bin/php -d register_argc_argv=On artisan schedule:run >> /dev/null 2>&1

0 likes
4 replies
Snapey's avatar
Snapey
Best Answer
Level 122

What doesRemoveOldMessages look like?

call is expecting it to be an invokable class or a closure

Try it like this instead

$schedule->call(function() {
	    removeOldMessages();
    })
    ->cron('0 2 * * *')
    ->name('removeoldmessages')
    ->withoutOverlapping()
    ->onOneServer();
1 like
hameti's avatar

doesRemoveOldMessages() is a function that returns true if successful and false otherwise

hameti's avatar

I guess your solution worked, hooray!

I will mark your reply as the answer and come back to you if the issue persists.

Thanks a lot

Please or to participate in this conversation.