Welcome Guest, Not a member yet? Register   Sign In
Cron Library
#21

[eluser]Phil_B[/eluser]
Version 0.5 should be up soon.

I'm open to any suggestions for executing the jobs. The ME method works perfectly for me but I know others will want to use it in other ways. I would like to keep it platform independent so if I use exec, the parameter for forking would have to come from the users database entry.
#22

[eluser]sophistry[/eluser]
job execution options OTTOMH (i have used all of these at one time or another):
ME run (current implementation)
function call by variable $$funcname
method call by variable $obj->$methname
eval($code)
file_get_contents($url)
redirect($url)
call_user_func()
call_user_func_array()
exec() (and others like it, shell(), passthru(), etc...)

i tend to favor call_user_func_array()because it is the most flexible for calling things "internally" to the existing CI stack. file_get_contents() and redirect() will create a new CI process (assuming you are running CI jobs on your existing site). eval() i generally avoid.

cheers.
#23

[eluser]yannyannyann[/eluser]
I am new to cron jobs ...

I implemented this :

Code:
function config( $var = '' )
    {    
        if( $var == 'create' )
        {
            $this->cron->save_job(0, 'test every minutes', '* * * * *', base_url().'encoder' );    
        }
        $this->cron->load_jobs();
        $this->cron->run_jobs();        
    }

How can I verify the cron is done ?
#24

[eluser]sophistry[/eluser]
finally getting around to implementing this library. it's really cool except for a few errors i encountered and fixed:

the constructor $time->now setting needs to be changed so strtotime() can calculate the timestamp properly (it was giving me -1):
Code:
$this->now = strtotime(date('m/d/Y H:i:').'00 +1 minute'); // Round up to the next minute

i changed the line in run_jobs() where this library uses ME to run the jobs to a more generic file_get_contents(). this line will call any controller in your site (creates a new http process, but it means you don't have to have ME to use this cool cron setup):
Code:
// changed job caller to use file_get_contents()
            $url = site_url().$job['action'];
            $ret = file_get_contents($url);

the expand() function uses a weird reference trick in the foreach loop to avoid creating another variable. it was causing errors for me so i just created a temporary array called $expanded_cron and built the arrays in there and then returned that variable:
Code:
/**
     * Expand a cron-expression into full array of allowed minutes, hours, days, months and weekdays
     * No ranges or wildcards after this process
     *
     * @access    public
     * @param    string    The cron expression to be expanded
     * @return    array        Expanded cron expression
     */
    function expand($expression)
    {
        // Month and weekday english names
        static $keywords = array(
            '3' => array( // Months
                '/(january|jan)/i'=>'1',
                '/(february|feb)/i'=>'2',
                '/(march|mar)/i'=>'3',
                '/(april|apr)/i'=>'4',
                '/(may)/i'=>'5',
                '/(june|jun)/i'=>'6',
                '/(july|jul)/i'=>'7',
                '/(august|aug)/i'=>'8',
                '/(september|sep)/i'=>'9',
                '/(october|oct)/i'=>'10',
                '/(november|nov)/i'=>'11',
                '/(decemeber|dec)/i'=>'12'
            ),
            '4' => array( // Weekdays
                '/(sunday|sun|su)/i'=>'0',
                '/(monday|mon|mo)/i'=>'1',
                '/(tuesday|tue|tu)/i'=>'2',
                '/(wednesday|wed|we)/i'=>'3',
                '/(thursday|thu|th)/i'=>'4',
                '/(friday|fri|fr)/i'=>'5',
                '/(saturday|sat|sa)/i'=>'6'
            )
        );
        
        // High and low ranges for each segment type
        static $ranges = array(
            '0'=>array(0,59),    // Minute
            '1'=>array(0,23),    // Hour
            '2'=>array(1,31),    // Day
            '3'=>array(1,12),    // Month
            '4'=>array(0,6)    // Weekday
        );
        
        $cron = preg_split('/\s/', $expression);
        
        if (count($cron) != count($ranges))
        {
            show_error('Cron: Invalid number of segments in expression');
        }
        
        // 20100127 added expanded_cron var bc
        // the original code was doing something funky
        // with references that was causing errors
        // this is simple - just make a new array
        $expanded_cron = array();
        foreach($cron as $index=>$segment)
        {
            $expanded = array();
            
            $parts = preg_split('/,/', $segment);
            foreach($parts as $part)
            {
                // Convert keywords to nubmers
                if (isset($keywords[$index])) {$part = preg_replace(array_keys($keywords[$index]), array_values($keywords[$index]), $part);}
                
                // Convert wildcards to ranges
                $part = preg_replace('/^\*(\/\d+)?$/i', $ranges[$index][0].'-'.$ranges[$index][1].'$1', $part);
                // Expand ranges
                if (preg_match('/^(\d+)-(\d+)(\/(\d+))?/i', $part, $matches))
                {
                    $low = $matches[1];
                    $high = $matches[2];
                    $step = isset($matches[4]) ? $matches[4] : 1;
                    
                    for($i = $low; $i <= $high; $i += $step)
                    {
                        $expanded[] = $i;
                    }
                }
                else
                {
                    $expanded[] = $part;
                }
            }
            
            $expanded = array_unique($expanded);
            sort($expanded);
            
            // 20100127 added expanded_cron array
            //$segment = $expanded;
            $expanded_cron[$index] = $expanded;
        }
        
        // 20100127 added
        return $expanded_cron;
    }
#25

[eluser]dardar[/eluser]
Download link is not working, maybe someone could upload it somethere else or maybe it's board's problem?
#26

[eluser]InsiteFX[/eluser]
All WIKI files have been moved here to the new WIKI

CodeIgniter WIKI - GitHub
#27

[eluser]Pedroshow[/eluser]
Can someone tell me why I cant download it?




Theme © iAndrew 2016 - Forum software by © MyBB