Command Line Application with common features built using phalcon framework.
Features
- Easily Record cli application output to the database
- Easily force your application to run one instance at a time (handles fatal errors properly releasing the pid file)
- Easily output debug information (even if your application has a fatal/runtime error)
General Syntax for running a task/job (Note: only Task is required)
cd phalphp/private
php cli.php [Task] [Action] [Param1] [Param2] [...]Tasks are stored in phalphp/app/tasks directory. The following example task is named ExampleTask.php.
Basic example of how to kick off a cli job/task.
cd phalphp/private
php cli.php Example test1 Passing parameters to your application
php cli.php Example test2 bob sanders Enable debug mode to see a more detailed overview of what is going on --debug
This also enables a more verbose level of php reporting, displaying all php warnings.
php cli.php Example cmd --debugRecord all output to the database (in the task table) --record .
php cli.php Example test1 --recordOnly allow 1 instance to run at a time --single
php cli.php Example test1 --singleEnable all flags
php cli.php Example test1 --debug --record --singleGo to phalphp/app/tasks directory. This is where all the tasks are stored.
Just go ahead and create a new file here (eg. NewTask.php)
<?php
namespace Tasks;
use \Cli\Output as Output;
class NewTask extends \Phalcon\Cli\Task {
public function workAction() {
Output::stdout("hi");
}
}
?>Now run it!
cd phalphp/private
php cli.php New workNote: All classes must be namespaced if you use the provided autoloader.
Open phalphp/app/config/autoload-cli.php and an element to the existing array.
So, you have to use namespacing to load new classes.
$autoload = [
'Utilities\Debug' => $dir . '/library/utilities/debug/',
'Trend' => $dir . '/library/trend/'
];
return $autoload;