Donations appreciated Bitcoin: 1EBCsnpYftigYFSpZtXWFjRTAgPb3EdZZh
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)
PHP 5.4 or greater
Required PHP Modules
- Phalcon (http://phalconphp.com/en/download)
- PDO (MySQL or Postgres or Sqlite driver)
To check if phalcon
module is installed/enabled for CLI use
$ php -m | grep -i "phalcon"
phalcon
Open php-cli-app-phalcon/app/config.php
and edit your database connection credentials
$settings = array(
'database' => array(
'adapter' => 'Mysql', /* Possible Values: Mysql, Postgres, Sqlite */
'host' => 'your_ip_or_hostname',
'username' => 'your_user',
'password' => 'your_password',
'name' => 'your_database_schema',
'port' => 3306
),
);
Import the tables into your MySQL Server
mysql -u root -p your_database_schema < php-cli-app-phalcon/mysql.data.sql
Import the tables into your Postgres Server
psql -U root -W -f postgres.data.sql your_database_schema
General Syntax for running a task/job (Note: only Task is required)
cd php-cli-app-phalcon/private
php cli.php [Task] [Action] [Param1] [Param2] [...]
Tasks are stored in php-cli-app-phalcon/app/tasks
directory. The following example task is named ExampleTask.php
.
Basic example of how to kick off a cli job/task.
cd php-cli-app-phalcon/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 --debug
Record all output to the database (in the task
table) --record
.
php cli.php Example test1 --record
Only allow 1 instance to run at a time --single
php cli.php Example test1 --single
Enable all flags
php cli.php Example test1 --debug --record --single
Go to php-cli-app-phalcon/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 php-cli-app-phalcon/private
php cli.php New work
Note: All classes must be namespaced if you use the provided autoloader.
Open php-cli-app-phalcon/app/config/autoload.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;