How Arcos works
This topic is for those people who like to know what happens behind the scenes. You do not need to know this to use Arcos, although you will find it useful for resolving problems.
From the XML file to the generated page
This is what happens when you request a page:
- The browser makes a request to the web server for a page.
- The Apache .htaccess file in the html directory rewrites the request to call dispatch.php instead.
- If the file exists in the html directory, dispatch.php includes and runs the file for the original request.
- If the file does not exist, dispatch.php initialises K_Manager, which performs these steps:
- K_Manager calls a method called check_versions to determine whether the configuration file has been modified.
- If it has, K_Manager instantiates K_Structure, which in turn instantiates XML_Config which uses xml_parser.lib to reparse the XML into an array.
- A CheckDependancies method in K_Structure retrieves the cached K_Checksums object from the cache, if it exists, and uses this to find out what structures (tables, recordsets, pages) have changed.
- The structures that have changed are recreated and cached.
- dispatch.php calls the ProcessTransactions method of K_Manager with a string containing the original request.
- The ProcessTransactions method examines the Transaction ID passed in the state to see if there is a transaction in place (that is, a form submission).
- If there is a transaction, K_Manager invokes the page for the Transaction ID (using the ShowPage method) and ignores the original request (because Arcos pages only submit to themselves). (This means that URLs and page names do not necessarily correspond to one another; the Arcos page that is being displayed may not necessarily match the URL in the browser window.)
- If there is no transaction, K_Manager invokes the Arcos page for the original request using the ShowPage method of K_Manager.
- The ShowPage method runs the cache file for a page (which will exist in the pagehack directory if it has been moved there).
The generated page
Generated pages reside in the cache directory. They are quite complex; here we outline the general principles.
Transactions
A transaction is a form submission from a page to itself (all pages in Arcos handle their own form submissions, even if a different destination has been set in the form's tag). If the page has received a transaction, it must validate the form data that has been posted to it and then carry out any actions attached to the button that has been pressed. If the page has not received a transaction, it can just display the rest of the page as normal.
The transaction modify flag
If a user clicks a form button more than once, or goes back and then forwards again from the form, the form could be submitted more than once. This is dangerous because a particular action relying on the submission may be performed twice. For example, the user could pay for some goods twice.
Arcos guards such sensitive actions by reserving a special section of the page that is protected by the transaction modify flag. The first time the form is submitted, the section is executed, and the transaction modify flag for that submission is set to true, so that if this form is submitted again the section is not run.
This works by generating a hash value for the form values that are submitted for the page. These transaction hash values are stored in the Session, so Arcos knows whether it has previously seen a particular form submission for a page.
Recordset and component IDs
Each recordset and component defined in the XML is assigned a unique ID number. These are used in page generation to create a unique variable names and indexes to arrays.
Concepts:
Home |
Previous