Console command call in background

Posted 3 years ago by dmitry.g.ivanov

Hi there!

If you need to call artisan command from code, you can use Laravel Artisan facade class: https://laravel.com/docs/5.2/artisan#calling-commands-via-code

But what about background calls?

I've made a simple helper function for that.

call_in_background() Calls artisan console command in background, with optional before and after sub-commands:

call_in_background('foo');

// "php artisan foo" would be called in background
call_in_background('foo:bar baz', 'sleep 0.3');

// "sleep 0.3 && php artisan foo:bar baz" would be called in background

If you'd like to use it, this helper is available in my package with other helper functions:

https://github.com/dmitry-ivanov/laravel-helper-functions

https://packagist.org/packages/illuminated/helper-functions

Hope it would be useful for someone. Thanks and have a great day!

Please sign in or create an account to participate in this conversation.