Command Line Applications

Command Line Applications

CLI applications are executed from the command line. They are useful to create cron jobs, scripts, command utilities and more.

Structure

A minimal structure of a CLI application will look like this:

  • app/config/config.php
  • app/tasks/MainTask.php
  • app/cli.php <– main bootstrap file

Creating a Bootstrap

As in regular MVC applications, a bootstrap file is used to bootstrap the application. Instead of the index.php bootstrapper in web applications, we use a cli.php file for bootstrapping the application.

Below is a sample bootstrap that is being used for this example.

use Phalcon\Di\FactoryDefault\Cli as CliDI;
use Phalcon\Cli\Console as ConsoleApp;
use Phalcon\Loader;



// Using the CLI factory default services container
$di = new CliDI