Framework: Artisan::call('horizon:terminate') The command "horizon:terminate" does not exist.

Created on 14 Apr 2019  路  8Comments  路  Source: laravel/framework

  • Laravel Version: 5.8.11
  • PHP Version: 7.2.14

Description:

Calling this from my application will cause this error

        Artisan::call('horizon:terminate');

Symfony \ Component \ Console \ Exception \ CommandNotFoundException
The command "horizon:terminate" does not exist.

When i call the command from the command line it works.

If you ask why i'm calling the horizon:terminate from my application, well i have a settings module that allows users to update the application configuration by updating the .env file.

After doing so,
I want to do two things

        Artisan::call('config:cache');
        Artisan::call('horizon:terminate');

The config:cache works but the horizon:terminate does not.

Most helpful comment

Ran into the same issue (with another package).

It seems only commands registered outside of the if ($this->app->runningInConsole()) call are available to be called from within the app's runtime with Artisan:call.

Made a little write up explaining my solution.

In my case, I'm the maintainer of the package and could easily work around the limitation by taking the command I want to use in Laravel out of the if statement.

But I just tested that you can register the horizon:terminate command yourself in your app's $commands array in app/Console/Kernel.php.

For instance, I did this.

protected $commands = [
    \Nonoesp\Folio\Commands\CreateUserCommand::class,
];

While the CreateUserCommand is only registered to the console by the package, I can explicitly make it available for my entire application calling it with Artisan::call('folio:user {email} {password}') (which is this command's signature).

All 8 comments

You need to have Horizon installed for this. This is the issue tracker for the Laravel framework, not Horizon.

@driesvints That is the problem, Horizon is already installed and it says command not found

Can you first please try one of the following support channels? If you can actually identify this as a bug, feel free to report back and I'll gladly help you out.

Thanks!

@shadoWalker89 Not sure where you're calling that Artisan command, but you can only call that through the "terminal".

Hope this https://github.com/laravel/horizon/blob/3.0/src/HorizonServiceProvider.php#L168 helps to understand the cause perhaps?

@brunogaspar Thanks, that explains why i'm getting command not found.

For now what i'm doing

exec('cd '.base_path().' && /usr/local/bin/ea-php72 artisan horizon:terminate');

@brunogaspar About why i'm calling that command, like i said in the issue message, the administrator of the application can change configurations saved within the .env file. I need to terminate horizon so it can pickup the new config values

Yup, figured much.

Your solution is not bad, although not super Laravel Clean :)

Ran into the same issue (with another package).

It seems only commands registered outside of the if ($this->app->runningInConsole()) call are available to be called from within the app's runtime with Artisan:call.

Made a little write up explaining my solution.

In my case, I'm the maintainer of the package and could easily work around the limitation by taking the command I want to use in Laravel out of the if statement.

But I just tested that you can register the horizon:terminate command yourself in your app's $commands array in app/Console/Kernel.php.

For instance, I did this.

protected $commands = [
    \Nonoesp\Folio\Commands\CreateUserCommand::class,
];

While the CreateUserCommand is only registered to the console by the package, I can explicitly make it available for my entire application calling it with Artisan::call('folio:user {email} {password}') (which is this command's signature).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PhiloNL picture PhiloNL  路  3Comments

Anahkiasen picture Anahkiasen  路  3Comments

YannPl picture YannPl  路  3Comments

jackmu95 picture jackmu95  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments