5.0-Nano: Portable Cron

From The Uniform Server Wiki
Revision as of 21:55, 14 August 2009 by Ric (talk | contribs) (New page: {{Nav 5.0-Nano}} '''''5.0-Nano Portable Cron''''' Uniform Server’s portable Cron has been integrated into 5.0-Nano. It comes complete with two templates one for Drupal and other for Moo...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

 

5.0-Nano Portable Cron

Uniform Server’s portable Cron has been integrated into 5.0-Nano. It comes complete with two templates one for Drupal and other for Moodle. Well when I say templates they are two lines that require enabling to run the appropriate applications Cron script.

Portable Cron is binary mapped into UniServer’s control space; value assigned is 16 this method makes it easier to integrate with existing control blocks.

Starting Cron a default installation periodically runs scripts that are listed in file run_cron.php, the period being defined by a sleep function. This simple approach is effective however if you wish to add more flexibility this page provides additional information after explaining the basic operation and use.

Top

Cron

Cron originated from a Unix environment it is a job scheduler allowing scripts to be run automatically at a certain time or date.

Cron (chronograph) has become a more general term referring to a periodic tick.

Top

Portable Cron

For a permanent installation of UniServer running as a service you can set-up Windows to schedule a task similar to Unix Cron check out How To Schedule Tasks in Windows XP for details?

This is not practical when running UniServer from a USB memory stick. UniServer 5.0-Nano resolves this with a small script scheduler referred to as portable Cron.

It’s fully integrated into UniServers’s control architecture allowing it to be run from either batch files or UniTray.

To run a script or scripts a small amount of configuration is required as explained below.

Top

Configuration

Each script that requires running is added to the Cron script run_cron.php located in folder UniServer\unicon\main

Edit this file, there are two example lines use these as a template.

Enable a line by removing the two forward slashes. Insert a script’s full url (effectively this is what you would type into a browser to run an applications Cron script).

The two enabled example lines as follows:

 $dummy = file("http://localhost/moodle/admin/cron.php"); // Uncomment to enable 
 $dummy = file("http://localhost/drupal/cron.php");       // Uncomment to enable 

The variable $dummy is just that and is never used.

Note 1: If you have installed the above applications to different folders use the appropriate folder names.

Note 2: If you have moved the servers remember to add a port number to the url.

For example moving the servers once, Apache port becomes 81 and the above two lines need to change as follows:

      
 $dummy = file("http://localhost:81/moodle/admin/cron.php"); // Uncomment to enable 
 $dummy = file("http://localhost:81/drupal/cron.php");       // Uncomment to enable

Top

Periodic tick

Starting Cron immediately runs all scripts defined in the list. After this, scripts will run periodically defined by variable $cron_time currently set to 15 seconds.

This is a low value suitable only for testing, set a value that is appropriate for the application scripts you are running.

Top

Running Cron

Start the servers and run cron from either the batch files or UniTray

UniTray

  • Start: Left click tray icon > Advanced > click Run Portable Cron
  • Stop: Left click tray icon > Advanced > click Stop Portable Cron

Batch files

Navigate to folder UniServer\alternative_control

  • Start: Double click Start_Cron.bat
  • Stop: Double click Stop_Cron.bat

Note: There can be a delay of up to one second before cron stops.

Top

General Notes

Binary coded

Control architecture, for independent control Cron has been binary coded with a value of 16.

Example of use

If you wish to start and stop Cron when starting and stopping both servers from UniTray

edit file UniServer\unicon\tray_menu\UniTray1.ini

Change these two lines (Note lines are split so as not to break Wiki formatting):

From:

 Type: item; Caption: "Start UniServer (Apache MySQL)"; Action: shellexecute;
 FileName: "%PHP%\php.exe"; Parameters: " -n %ServerConMain%\start_servers.php 7";
 ShowCmd: hidden; Glyph: 9

 Type: item; Caption: "Stop  UniServer (Apache MySQL)"; Action: shellexecute;
 FileName: "%PHP%\php.exe"; Parameters: " -n %ServerConMain%\stop_servers.php 7";
 ShowCmd: hidden; Glyph: 11

To:

 Type: item; Caption: "Start UniServer (Apache MySQL)"; Action: shellexecute;
 FileName: "%PHP%\php.exe"; Parameters: " -n %ServerConMain%\start_servers.php 23";
 ShowCmd: hidden; Glyph: 9

 Type: item; Caption: "Stop  UniServer (Apache MySQL)"; Action: shellexecute;
 FileName: "%PHP%\php.exe"; Parameters: " -n %ServerConMain%\stop_servers.php 23";
 ShowCmd: hidden; Glyph: 11

Only change required is the parameter value passed to a script. Although I have shown UniTray it also applies to batch files contained in folder UniServer\alternative_control

Note: Binary 1+2+4+16 = 23

  1 - Run Apache server
  2 - Run MySQL server
  4 - Start Index page
16 - Run cron

Portable Cron and Service

Portable Cron may be run when servers are installed as a service.

However will not restart after restarting PC, you need to manually run Portable Cron again.

Top

Summary

Top