Klaus
Klaus

Reputation: 439

How can I run a php artisan command in the background from controller?

I'm trying to figure out a way I can set a artisan command to run in the background when a user does an action, if I run the artisan call method the browser will just load untill it's done.

What I want to do is would similar this to in the terminal:

php artisan fix > /dev/null 2>&1 &

But run it from the controller instead, is that possible?

Btw. I know I could just setup a cronjob to run it, but I really want to run it from the controller.

Upvotes: 3

Views: 4606

Answers (1)

Hooman
Hooman

Reputation: 371

You could run a background || async task using laravel queues:

https://laravel.com/docs/5.7/queues

Upvotes: 3

Related Questions