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

tgbv's avatar
Level 1

Laravel Task Scheduler: managing tasks which take longer than one minute to execute?

Hello! I hope this question is not a duplicate. I'm using Laravel Task Scheduler. It's stated in documentation that:

This Cron will call the Laravel command scheduler every minute. When the schedule:run command is executed, Laravel will evaluate your scheduled tasks and runs the tasks that are due.

Suppose I run a query which calls a stored procedure from a database and operation takes longer than one minute. Do the newly spawned processes kill themselves automatically to give the working process time to finish the calls or do I have to manage this case on my own? How could I do that?

0 likes
2 replies
Talinon's avatar
Talinon
Best Answer
Level 51

@tgbv Regardless if Cron is calling every minute, you can configure Laravel's Task Scheduler to execute your tasks whenever, or however frequently you desire. If there is nothing scheduled, Task Scheduler will just close and wait for the next call from Cron.

So, if you have a long running script, just make a task entry for something that runs every 2 minutes, or 5 minutes, or however long you think it needs.

For example:

$schedule->command('my-command')->everyFiveMinutes();

Cron can call Task Scheduler to run every minute, but that command will only execute once every five calls.

To answer your question, no it will not kill processes already running.

If the length of time to process is too much of a variable, then you could consider making some kind of process mutex, drop file, or lock-entry in a database to let future processes know that there is a job in progress and to die immediately.. so yes, handle it yourself in some way.

1 like

Please or to participate in this conversation.