Command Line Dispatcher (Symfony)

It is possible to run some TYPO3 CMS scripts from the command line. This makes it possible - for example - to set up cronjobs.

TYPO3 uses Symfony commands to provide an easy to use, well-documented API for writing CLI (command line interface) commands.

Creating a new Symfony Command in Your Extension

  1. Add Configuration/Commands.php to your extension

    TYPO3 looks in this file for configured commands. It should return a simple array with the command name and class.

    For example to add a command named yourext:dothings :

    return [
        'yourext:dothings' => [
            'class' => \Vendor\Extension\Command\DoThingsCommand::class
        ],
    ];
    

    By default, the command can be used in the scheduler too. You can deactivate this by setting schedulable to false :

    return [
        'yourext:dothings' => [
            'class' => \Vendor\Extension\Command\DoThingsCommand::class,
            'schedulable' => false,
        ]
    ];
    
  2. Create the corresponding class file: Classes/Command/DoThingsCommand.php

    Symfony commands should extend the class Symfony\Component\Console\Command\Command .

    The command should implement at least a configure and an execute method.

    configure() as the name would suggest allows to configure the command. Via configure() , a description or a help text can be added, or mandatory and optional arguments and parameters defined.

    A simple example can be found in the ListSysLogCommand :

    /**
     * Configure the command by defining the name, options and arguments
     */
    protected function configure()
    {
        $this->setDescription('Show entries from the sys_log database table of the last 24 hours.');
        $this->setHelp('Prints a list of recent sys_log entries.' . LF . 'If you want to get more detailed information, use the --verbose option.');
    }
    

    execute() contains the logic you want to execute when executing the command.

See also

A detailed description and an example can be found in the Symfony Command Documentation .

Running the Command From the Command Line

The above example can be run via command line:

bin/typo3 yourext:dothings

Running the Command From the Scheduler

By default, it is possible to run the command from the TYPO3 scheduler as well if ( schedulable is not set to false).

In the backend: SYSTEM > Scheduler