Skip to content

jeteokeeffe/php-cli-app-phalcon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-cli-app-phalcon

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)

Requirements

PHP 5.4 or greater

Required PHP Modules

To check if phalcon module is installed/enabled for CLI use

$ php -m | grep -i "phalcon"
phalcon

Database Configuration

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

Command Line Examples

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 

Special Flags

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

Adding New Tasks

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

Adding New Classes to Autoload

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;

About

Command Line Application built using phalcon framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages