Giter Club home page Giter Club logo

cronrunner's Introduction

Cronrunner

php cli framework,compenont manager,scalable tools

##Requirement

  • PHP 5 +
  • pcntl

Tutorial

layout

- config.php // Application config
- common.php
+ lib // Application library
  | + core // core library
  | + component // Configurable compnent
  | + utils // some tools,you must explicitly include them 
+ include // User defined library
+ bin // application
+ log 
+ tmp
+ data
+ www // www virtual directory 

example

bin/testFramework.php

<?php
require '../common.php';
$app = CApp::create($appRoot, $sysConfig);
$app->init('TestFramework');// Job Factory, or **$app->init('TestFramework', $params_array);**to set some parameters
$app->run();

include/TestFramework.php

<?php
class TestFrameworkJob extends CJob {
    public function jobAction()
    {
        echo "hello framework!\n";
        sleep(10);
        // using getAllParams() to get all Job parameters
        // var_dump($this->getAllParams());
        // var_dump($this->getParams('test'));
        $this->_appInstance->logger->log("test log INFO", "NOTICE");
        return 1;
    }
}

configurable modules

here is a example of module config

<?php
// module config section
'modules' => array(
    // @logger:ERROR->NOTICE->WARNNING->EXCEPTION->INFO->ALL
    // log level does inverse relationship with LogLevel number value
    'logger' => array(
        'logOn'         => true, // logger switcher
        'logLevel'      => 5,
        // print in screen if it's setted to true
        'logInShell'    => true,
        // logrotate by month switcher
        'logFormatMonth'=> false,
        // logrotate by day switcher
        'logFormatDay'  => true,
        // backtrace swithcer
        'backtrace'     => true,
    ),
    // Mongo config example 
    'mongo_test' => array(
        'class' => 'CMongo',    
        'mongoConf' => array(
            // db is the database name to authentica
            'dsn' => 'mongodb://user:psw@host:port/db',
            // db1 is the database to select 
            'options' => array('db' => 'db1', 
                'connectTimeoutMS' => 5000, 'w' => 1,
            ),
        ),
    ),
),

module using example

include/MongoTest.php

<?php
// class name must be same to file name
class MongoTest extends CJob {
    public function jobAction() {
        // Mongodb connection handler,connect mongodb lazily
        $db = $this->_appInstance->mongo_test->mongoDb;     
        $collection = $this->getParams('collection');
        var_dump($db->$collection->findone());
    }
}

bin/mongo_test.php

<?php
$inc_file = sprintf('%s/../common.php', dirname(__FILE__));
require $inc_file;
$app = CApp::create($appRoot, $sysConfig);
$args = array('collection' => $argv[1]);
$app->init('MongoTest', $args);
$app->run();

cronrunner's People

Contributors

ruibin avatar

Stargazers

redoufu avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.