Previous | Up | Next |
Configuration | Configuration |
mach-ii.xml
|
mach-ii.php
mach-ii.php
mach-ii.php
The mach-ii.php
file is the entry point for a request to the Mach-II framework. There are three important parameters for the application and the framework that should be set in mach-ii.php
. They are: $MACHII_CONFIG_PATH
, $MACHII_CONFIG_MODE
and $MACHII_APP_KEY
. Finally, the application cache must be configured.
$MACHII_CONFIG_PATH
$MACHII_CONFIG_PATH
must be set to the absolute path and filename of the XML configuration file. This can be accomplished in PHP by passing a relative path to the file to http://www.php.net/realpath.
- /**
- * Sets the path to the config file
- */
- $MACHII_CONFIG_PATH = realpath('./config/mach-ii.xml');
$MACHII_CONFIG_MODE
$MACHII_CONFIG_MODE
must be set to one of three possible constants:
MACHII_CONFIG_RELOAD_NEVER
Do not reload the configuration file. (recommended for production deployments)
MACHII_CONFIG_RELOAD_DYNAMIC
Reload the configuration file whenever it's updated by automatically checking the file's last modified date. (recommended for development)
MACHII_CONFIG_RELOAD_ALWAYS
Reload the configuration file on each request. (will result in significant performance penalties and is not recommended for production)
Each time the configuration is reloaded the application framework is re-instantiated. This means the configuration file is reread, parsed and a lot of object instances are created. This also means any state information held in framework components (such as listeners.pkg) will be reset if not persisted.
Note: This setting only effects reload of the configuration file. It will always be loaded when instantiating a new application.
- /**
- * Sets the config file reload mode
- */
- $MACHII_CONFIG_MODE = MACHII_CONFIG_RELOAD_DYNAMIC;
$MACHII_APP_KEY
$MACHII_APP_KEY
must be set to a value that is unique within the scope of the system being used to cache the application. This property allows multiple Mach-II applications, each independent of one another, to operate within one cache.pkg. The current path or config path is recommended.
- /**
- * Sets the config file reload mode
- */
- $MACHII_APP_KEY = realpath('.');
- /**
- * Or simply re-use the config path
- */
- $MACHII_APP_KEY = $MACHII_CONFIG_PATH;
A key feature for performance is to persist the configured application. This may be accomplished in several ways, one of which is the built-in static method, MachII::cache()
.
In it's simplest form, pass the three previously configured settings to MachII::cache()
and the application will be stored in a user session using MachII_cache_PhpSession
.
- /**
- * Prepare the cache and...
- *
- * If the application object exists in the
- * cache system restore it...
- * -OR-
- * Create a new application...
- *
- * Return the application object.
- */
- $appLoader =& MachII::cache(
- $MACHII_CONFIG_PATH,
- $MACHII_CONFIG_MODE,
- $MACHII_APP_KEY,
- 'PhpSession' // Optional, this is the default
- );
Because of the potential size and number of application objects that this system can create it is not the recommended cache container for production applications. Further, when using on a shared host, sensitive data should be stored in the application object with the same caution exersized in storing sensitive data in a session variable.
Note: MachII_cache_PhpSession will fail silently on PHP <4.1.0. The application will NOT be cached! Use an alternate application cache.
Additional caching systems may be downloaded or custom created for many different data persistence systems via a simple driver-type system. See the machiicache.pkg documentation for more information on creating custom cache drivers.
This example uses a downloadable driver that acts as an interface to Cache_Lite, a light-weight file-based cache class:
Previous | Up | Next |
Configuration | Configuration |
mach-ii.xml
|
Documentation generated on Thu, 20 Jan 2005 10:46:49 -0800 by phpDocumentor 1.3.0RC3