Cron Design: Cron Script Part 2: Difference between revisions

m
Reverted edits by Upazixorys (Talk); changed back to last version by Ric
No edit summary
m (Reverted edits by Upazixorys (Talk); changed back to last version by Ric)
 
Line 1: Line 1:
=[http://osobageqys.co.cc UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY]=
{{Nav Cron Design}}
{{Nav Cron Design}}
At the heart of Uniform Server’s portable Cron is a configuration file. This is periodically read into an array the period is defined by Cron time, which has a default setting of one minute. The array is scanned line-by-line comparing any time settings to the current time on finding a match the corresponding script is run.
At the heart of Uniform Server’s portable Cron is a configuration file. This is periodically read into an array the period is defined by Cron time, which has a default setting of one minute. The array is scanned line-by-line comparing any time settings to the current time on finding a match the corresponding script is run.
Line 10: Line 9:
Every time the script is run the configuration file is read into an array. First task of the foreach-loop is to extract a block’s option values. Each time around the loop selects a new block and extracts its option values.     
Every time the script is run the configuration file is read into an array. First task of the foreach-loop is to extract a block’s option values. Each time around the loop selects a new block and extracts its option values.     
{|
{|
|-valign="top"
|-valign="top"
|
|
'''''Read Configuration file'':'''
'''''Read Configuration file'':'''
Line 18: Line 17:
|
|
'''''Function Used'':'''
'''''Function Used'':'''
<pre>
<pre>


$ini_array = parse_ini_file($file, true);
$ini_array = parse_ini_file($file, true);


&lt;/pre&gt;
</pre>
|-valign=&quot;top&quot;
|-valign="top"
|
|
'''''Extract Option Value'':'''
'''''Extract Option Value'':'''
* Having the structure preserved means the array can be scanned with&amp;nbsp;&lt;br /&gt;a foreach loop that targets only the block title.
* Having the structure preserved means the array can be scanned with&nbsp;<br />a foreach loop that targets only the block title.
* Hence array '''$key''' holds a block title.
* Hence array '''$key''' holds a block title.
{|
{|
|-
|-
|
|
&lt;pre&gt;
<pre>
foreach($ini_array as $key =&gt; $value){  
foreach($ini_array as $key => $value){  
}  
}  
&lt;/pre&gt;
</pre>
|}
|}
* This $key is used to target options in the bock as follows:
* This $key is used to target options in the bock as follows:
Line 40: Line 39:
|-
|-
|
|
&lt;pre&gt;
<pre>
$tim = strtotime(&quot;now&quot;);        //current time
$tim = strtotime("now");        //current time
$tim_s  = strtotime($ini_array[$key]['start']);
$tim_s  = strtotime($ini_array[$key]['start']);
$period = $ini_array[$key]['period'];
$period = $ini_array[$key]['period'];
$path  = $ini_array[$key]['path'];
$path  = $ini_array[$key]['path'];
$ref    = $ini_array[$key]['ref'];
$ref    = $ini_array[$key]['ref'];
&lt;/pre&gt;
</pre>
|}
|}
'''''Note'':''' All times are converted to Unix timestamps.
'''''Note'':''' All times are converted to Unix timestamps.
Line 54: Line 53:
|
|
'''''Configuration file example'':'''
'''''Configuration file example'':'''
&lt;pre&gt;
<pre>


[dtdns]
[dtdns]
Line 80: Line 79:
ref =  
ref =  
    
    
&lt;/pre&gt;
</pre>
|}
|}
'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
Line 86: Line 85:
== Froreach logic ==
== Froreach logic ==
{|
{|
|-valign=&quot;top&quot;
|-valign="top"
|
|
'''''Description'':'''
'''''Description'':'''
Line 115: Line 114:
== Froreach logic - Alternative flow diagram==
== Froreach logic - Alternative flow diagram==
{|
{|
|-valign=&quot;top&quot;
|-valign="top"
|
|
'''''Description'':'''
'''''Description'':'''
Line 124: Line 123:


'''''Code Snippet'':'''
'''''Code Snippet'':'''
&lt;pre&gt;
<pre>
$ini_array = parse_ini_file($file, true); // Read cron.ini into array
$ini_array = parse_ini_file($file, true); // Read cron.ini into array
foreach($ini_array as $key =&gt; $value){    // Scan array's main keys
foreach($ini_array as $key => $value){    // Scan array's main keys


  $tim = strtotime(&quot;now&quot;);                        //current time
  $tim = strtotime("now");                        //current time
  $tim_s  = strtotime($ini_array[$key]['start']); // Start time
  $tim_s  = strtotime($ini_array[$key]['start']); // Start time
  $period = $ini_array[$key]['period'];          // Period
  $period = $ini_array[$key]['period'];          // Period
Line 134: Line 133:
  $ref    = $ini_array[$key]['ref'];              // Repeat time marker
  $ref    = $ini_array[$key]['ref'];              // Repeat time marker


if((float)$tim &gt; (float)$tim_s){    // New start or started
if((float)$tim > (float)$tim_s){    // New start or started
   if( $ref != &quot;&quot;){                  // It was started
   if( $ref != ""){                  // It was started
     if( (float)$tim &lt; (float)$ref ){ // Is it a triggered update  
     if( (float)$tim < (float)$ref ){ // Is it a triggered update  
       continue;                      // No: Start next foreach
       continue;                      // No: Start next foreach
     }
     }
Line 148: Line 147:
}//if
}//if
}// End foreach
}// End foreach
&lt;/pre&gt;
</pre>


|
|