Revision: Sat, 02 Jul 2022 10:45:30 GMT

Console - Installation and Configuration

All of the provided application skeletons include the Console component by default. To enable component in alternative builds make sure to require composer package spiral/console and modify the application bootloader:


Make sure to include this bootloader at last, as it will also activate the set of default commands for previously added components.

To invoke application command run:

$ php app.php command:name

To get a list of available commands:

$ php app.php

To get help about the particular command:

$ php app.php help command:name

Invoke in Application

You can invoke console commands inside your application or application tests. This approach can be useful to create mock data for tests or automatically pre-configure the database.

Use Spiral\Console\Console to do that:

use Spiral\Console\Console;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;

// ...

public function test(Console $console)
    $input = new ArrayInput(['args' => 'value']);
    $output = new BufferedOutput();

    return $console->run($command, $input, $output);


Spiral Console dispatcher built at the top of powerful Symfony Console component.

You can register native Symfony Commands in your CLI application.


To apply the custom configuration to the Console component use Spiral\Config\ConfiguratorInterface or create a config file in app/config/console.php:

return [
     // application name
     'name'      => null,

     // application version
     'version'   => null,

     // list of application commands (if auto-discover disabled)
     'commands'  => [],

     // list of commands and sequences to run in `app configure`
     'configure' => [],

     // list of commands and sequences to run in `app update`
     'update'    => []

You can modify some of these values during application bootload via Spiral\Bootloader\ConsoleBootloader. To register new user command:

public function boot(ConsoleBootloader $console)

Note, by default Console component use auto-discovery mode to find all user commands in app/ automatically.

To register command in configure/update sequence:

public function boot(ConsoleBootloader $console)
  $console->addUpdateSequence('my:command', '<info>Running my:command...</info>');

Connection with RoadRunner

Please note, console commands invoked outside of the RoadRunner server. Make sure to run an instance of application server if any of your commands must communicate with it.

Edit this page