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

ilex01's avatar

How do I run a php file inside a schedule task?

Kernel.php:

$schedule->call(function () {
	// run a php file here
})->daily();

https://laravel.com/docs/8.x/scheduling#defining-schedules

0 likes
5 replies
Tray2's avatar

Why not just put the code you want executed in there instead of a external file?

ilex01's avatar

@Tray2 Because the following code doesn't work:

    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function () {

            DB::table('classement')->delete();

        })->everyMinute();
    }
Tray2's avatar

@ilex01 Any error messages?

And if you want to delete everything in the table truncate is faster.

Please or to participate in this conversation.