https://wiki.uniformserver.com/index.php?title=Cron_Design:_Running_Cron&feed=atom&action=historyCron Design: Running Cron - Revision history2024-03-29T14:41:31ZRevision history for this page on the wikiMediaWiki 1.41.0https://wiki.uniformserver.com/index.php?title=Cron_Design:_Running_Cron&diff=4937&oldid=prevOlajideolaolorun: Reverted edits by Upazixorys (Talk); changed back to last version by Ric2010-11-24T17:46:38Z<p>Reverted edits by <a href="/Special:Contributions/Upazixorys" title="Special:Contributions/Upazixorys">Upazixorys</a> (<a href="/index.php?title=User_talk:Upazixorys&action=edit&redlink=1" class="new" title="User talk:Upazixorys (page does not exist)">Talk</a>); changed back to last version by <a href="/User:Ric" title="User:Ric">Ric</a></p>
<a href="https://wiki.uniformserver.com/index.php?title=Cron_Design:_Running_Cron&diff=4937&oldid=4855">Show changes</a>Olajideolaolorunhttps://wiki.uniformserver.com/index.php?title=Cron_Design:_Running_Cron&diff=4855&oldid=prevUpazixorys at 10:19, 24 November 20102010-11-24T10:19:35Z<p></p>
<a href="https://wiki.uniformserver.com/index.php?title=Cron_Design:_Running_Cron&diff=4855&oldid=3903">Show changes</a>Upazixoryshttps://wiki.uniformserver.com/index.php?title=Cron_Design:_Running_Cron&diff=3903&oldid=prevRic: New page: {{Nav Cron Design}} Both Cron start and stop requests are passed to a central control block for processing. This control block consists of two scripts '''start_servers.php''' and '''stop_s...2009-10-09T16:48:41Z<p>New page: {{Nav Cron Design}} Both Cron start and stop requests are passed to a central control block for processing. This control block consists of two scripts '''start_servers.php''' and '''stop_s...</p>
<p><b>New page</b></p><div>{{Nav Cron Design}}<br />
Both Cron start and stop requests are passed to a central control block for processing. This control block consists of two scripts '''start_servers.php''' and '''stop_servers.php''' these are located in folder UniServer\unicon\main. Further processing if required is handed on to the appropriate script or scripts.<br />
<br />
In terms of interfacing having a central control architecture provides consistency and reduces complexity. This page covers the Cron interface and control processing.<br />
<br />
== Binary coding ==<br />
Programs or batch files that run either of the control scripts '''start_servers.php''' or '''stop_servers.php''' must include a single binary coded parameter. If this parameter is missing defaults are used. A parameter overrides any default settings this allows independent control of a particular function.<br />
<br />
Currenty the following binary codes have been assigned:<br />
{|<br />
|-<br />
|<br />
<pre><br />
<br />
CODE Options are binary coded as follows:<br />
Bit function<br />
Apache 1 1 - Run Apache server 0 - ignore<br />
Mysql 2 1 - Run MySQL server 0 - ignore<br />
Index page 4 1 - Start Index page 0 - ignore<br />
MySQL Console 8 1 - Display console 0 - ignore<br />
Cron 16 1 - Run cron 0 - ignore<br />
<br />
</pre><br />
|<br />
Binary bit coding does not conform to the classic definition where 1 means on and 0 means off. Uniform Server uses 1 to mean perform the function while 0 means ignore and do nothing.<br />
<br />
Having two separate files start_servers.php and stop_servers.php respectively performs the on-off functionality.<br />
<br />
Defaults are set in file UniServer\unicon\main\includes\'''config.inc.php''' by the following lines:<br />
<br />
* $server_standard = 7;<br />
* $server_service = 7;<br />
|}<br />
'''''What does this techno babble mean''!'''<br />
<br />
Well if you run start_servers.php with '''no parameter''' it picks up the default from variable '''$server_standard''' which has a value of '''binary code 7'''.<br />
<br />
Splitting code 7 into its individual components gives '''1+2+4''' hence '''start_servers.php''' runs the following processes:<br />
<br />
* 1 Apache<br />
* 2 Mysql<br />
* 4 Index page<br />
<br />
Similarly running '''stop_servers.php''' with no parameter will stop the above running processes. <br />
<br />
Using binary coding offers single bit (process) control this is exploited when running Cron explained below.<br />
<br />
'''''[[#top | Top]]'''''<br />
== Running portable Cron ==<br />
With an understanding of the above we can look at running Cron in more detail.<br />
=== Manually ===<br />
Portable Cron is run from one of two locations.<br />
<br />
==== Alternative Control ====<br />
* Navigate to folder UniServer\alternative_control<br />
* To run Cron: Double click on Start_Cron.bat<br />
* To stop Cron: Double click on Stop_Cron.bat<br />
<br />
<br />
'''Start_Cron.bat''' contains the following line:<br />
<pre><br />
..\usr\local\php\php.exe -n ..\unicon\main\start_servers.php 16<br />
</pre><br />
* '''..\usr\local\php\php.exe -n''' Runs the PHP interpreter ('''php.exe''') with no ('''-n''') configuration file and runs the following file: <br />
* '''..\unicon\main\start_servers.php 16''' Script start_servers.php is run with parameter 16 (Runs only Cron) <br />
<br />
<br />
'''Stop_Cron.bat''' contains the following line:<br />
<pre><br />
..\usr\local\php\php.exe -n ..\unicon\main\stop_servers.php 16<br />
</pre><br />
* '''..\usr\local\php\php.exe -n''' Runs the PHP interpreter ('''php.exe''') with no ('''-n''') configuration file and runs the following file: <br />
* '''..\unicon\main\stop_servers.php 16''' Script stop_servers.php is run with parameter 16 (Stops only Cron) <br />
<br />
<br />
==== UniTray ====<br />
* Left or Right mouse click tray icon<br />
* To run Cron: Advanced > Start Portable Cron<br />
* To stop Cron: Advanced > Stop Portable Cron<br />
Have a peek inside Unitrays configuration file: UniServer\unicon\tray_menu\'''UniTray1.ini'''<br />
<br />
These two lines (split on purpose to prevent breaking the Wiki) control Cron start and stop. Only thing worth of note is they use binary code '''16'''<br />
<pre><br />
Type: item; Caption: "Start Portable Cron"; Action: shellexecute; FileName:<br />
"%PHP%\php-win.exe"; Parameters: " -n %ServerConMain%\start_servers.php 16"; Glyph: 9<br />
<br />
<br />
Type: item; Caption: "Stop Portable Cron"; Action: shellexecute; FileName:<br />
"%PHP%\php-win.exe"; Parameters: " -n %ServerConMain%\stop_servers.php 16"; Glyph: 11<br />
<br />
</pre><br />
<br />
'''''[[#top | Top]]'''''<br />
=== Automatic ===<br />
Cron can be configured to run automatically when the servers are started.<br />
<br />
Edit file UniServer\unicon\tray_menu\'''UniTray1.ini'''<br />
<br />
These four lines (lines three and four split on purpose to prevent breaking the Wiki) control Server Start and Stop.<br />
<br />
Change binary code from 7 to 23 for lines three and four.<br />
<pre><br />
;=== LEFT MENU ============<br />
[Menu.Left]<br />
<br />
Type: item; Caption: "Start UniServer (Apache MySQL)"; Action: shellexecute; FileName:<br />
"%PHP%\php.exe"; Parameters: " -n %ServerConMain%\start_servers.php 7";ShowCmd: hidden; Glyph: 9<br />
<br />
Type: item; Caption: "Stop UniServer (Apache MySQL)"; Action: shellexecute; FileName:<br />
"%PHP%\php.exe"; Parameters: " -n %ServerConMain%\stop_servers.php 7";ShowCmd: hidden; Glyph: 11<br />
</pre><br />
'''''[[#top | Top]]'''''<br />
<br />
== Cron Start Stop ==<br />
The control block consists of two scripts '''start_servers.php''' and '''stop_servers.php''' these are located in folder UniServer\unicon\main.<br />
<br />
When these scripts are run they process a parameter passed in the case of Cron they are looking for binary code 16.<br />
<br />
The appropriate sections are reproduce below along with a description of salient points.<br />
<br />
'''''[[#top | Top]]'''''<br />
=== start_servers.php - Cron Section ===<br />
{|<br />
|-valign="top"<br />
|<br />
* $server_operation contains either the parameter passed or default this is compared with binary 16 using the “binary & bit operator” On a match runs the block of code.<br />
* If Apache not running give up<br />
* If Cron already running again give up<br />
* Cron tracker is used to break out of an infinite while loop (covered later) <br />
* Cron requires further process hence is handed over to a detached process.<br />
* The cmd is built. uniserv.exe is used to hide this detached process.<br />
* pclose(popen($cmd,'r')) runs script run_cron.php as a detached hidden process<br />
<br />
'''''Note 1'':''' For testing the command can be switch making the process visible.<br />
<br />
'''''Note 2'':''' If a user turns PC off without closing the servers next time servers are run a clean up operation is performed. Hence this code is run '''set_cron_tracker("stop")''' see RUN APACHE SERVER section <br />
|<br />
&nbsp;<br />
|<br />
'''''start_servers.php'''''<br />
<pre><br />
// === RUN CRON ============================================================<br />
if ((int)$server_operation & 16 ){ // Cron enabled by config or parameter <br />
<br />
if(apache_running()){ // Only run cron if Apache running<br />
// otherwise ignore and exit quietly<br />
<br />
if(get_cron_tracker() == "run"){ // Cron already running<br />
print " Cron already running\n"; // Already running, give up<br />
}<br />
else{ // not running<br />
set_cron_tracker("run"); // set tracker to run<br />
print " Cron started \n"; // inform user<br />
<br />
// Test switch between the two: visibe<br />
//$cmd = 'start ..\..\usr\local\php\php.exe run_cron.php'; // Test<br />
<br />
// Test switch between the two: hidden<br />
$cmd = 'start uniserv.exe "..\..\usr\local\php\php.exe run_cron.php"';<br />
<br />
pclose(popen($cmd,'r')); // Start detatched process <br />
<br />
}<br />
}//End Apache running<br />
}// End run cron<br />
</pre><br />
|}<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
=== stop_servers.php - Cron Section ===<br />
{|<br />
|-valign="top"<br />
|<br />
* $server_operation contains either the parameter passed or default this is compared with binary 16 using the “binary & bit operator” On a match runs the block of code.<br />
* If Cron is running set the tracker to "stop"<br />
<br />
The cron script on detecting a tracker value of "stop" breaks out of an inifinatent while loop thus killing the process.<br />
|<br />
&nbsp;<br />
|<br />
'''''stop_servers.php'''''<br />
<pre><br />
<br />
// === Stop Cron ========================================================<br />
<br />
if ((int)$server_operation & 16 ){ // Cron enabled by config or parameter<br />
if(get_cron_tracker() == "stop"){ // Already stopped or not running<br />
print " Cron not running\n";<br />
}<br />
else{<br />
set_cron_tracker("stop"); // Is running signal to stop<br />
print" Cron stopped.\n"; // Inform user<br />
}<br />
}<br />
</pre><br />
|}<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
== Summary ==<br />
The above has explained how Cron integrates into Uniforms Servers control architecture and the selective nature of binary coding.<br />
<br />
A request to run Cron results in running a new detached process. Although a single script I have split it over a number of pages to explain each section in detail.<br />
<br />
[[Cron Design: Cron Script Part 1 |'''Next page''']] covers the fundamental building block, an infinite while loop.<br />
<br />
'''''[[#top | Top]]'''''<br />
<br />
[[Category: Uniform Server 5.0-Nano]]</div>Ric