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

Terumi's avatar

Running artisan commands sequentially

Hello, I have some artisan commands which delete some data from a database and perform a curl request to fetch and populate the database with data. What I need is to make them run in order, when one has finished, I need another to start. Now, I have a schedule running in Kerner.php but I reckon that things get messed up and my webserver doesn't populate until I restart it.

Right now I have the commands runing at xx:xx the other one at xx:xx+2 etc.

I think that I have to make a command that runs on xx:xx and calls all the commands one after the other, but I don't know how to do it.

Can anyone help? Thank you

0 likes
6 replies
willvincent's avatar
Level 54

either update your cron job so that it's something like this:

php artisan [command 1]; php artisan [command 2]

or drop it all into a bash script, and then call that script with cron:

something like scheduled_artisand_commands.sh:

#!/bin/bash

cd /path/to/project/root
php artisan your_first_command
php artisan your_second_command

chmod that +x so it's executable then update your crontab to execute that script at the desired time.

Easy peasy.

1 like
Ronster's avatar

Maby you can create 1 command that handles all other commands.

You can use Artisan::call('command:name'); to call a single command from within your application

jekinney's avatar

If command 1 doesn't return anything your second command May fire before the first one is up. Either call the second coo mad after the first in your first command or return true false for the first that will allow the second to run when true.

Terumi's avatar

yes, but how can I return thatr a command has ended? An after that what do I do? A while loop to see if the first one has ended?

willvincent's avatar

@Terumi Unless your artisan command exits prematurely, yes.

Basically the same idea as this, for example:

git clone git@github.com:laravel/framework.git; cd framework; ls

Obviously you couldn't cd into the directory before it's created and the repo cloned there.. that example would clone the laravel framework repo, cd into it, and then run an ls to display the contents.. same idea, really.

2 likes

Please or to participate in this conversation.