File/program/init.php

Description

/program/init.php - setup database connection, sessions, configuration, etc.

This file is included from one of the main entry points. The following subsystems and global variables are initialised:

  • connection to the database
  • session handler
  • $CFG
  • etc.
This file is included at a fairly early stage in the process. It does not rely on any regular libraries which are include()'ed lateron. That is: all relevant libraries (such aslwaslib.php are included when necessary from within the function initialise().

Functions
diff_microtime (line 320)

Calculate the difference between two microtimes

  • return: interval between the two times (in seconds)
double diff_microtime (string $time_start, string $time_stop)
  • string $time_start: starting time as a string (fractional seconds, space, seconds)
  • string $time_stop: ending time as a string (fractional seconds, space, seconds)
error_exit (line 278)

emergency exit of program in case there is something really, really wrong

This routine outputs a short message and a 'cryptic' condition code and exits the program. It is called when something goes horribly wrong during the early stages of running the program, e.g. the database cannot be opened or there is a version mismatch between the program code (the .php-files) and the database. The complete condition code is the WAS release number followed by a slash followed by the WAS version number followed by a slash and the bare condition code. The message ends with a link to about.html with 'Powered by' or 'Based on', depending on the WAS original flag. Note that we try to show graphics (including logo) but that we switch back to text-only if it is too early, ie. before waslib.php is included.

Here is an overview of meaning of the condition codes used.

  • 010: cannot find config.php, is W@S installed at all?
  • 015: cannot find program/main_XXXXX.php, is W@S installed at all?
  • 020: configuration error, invalid database type
  • 030: cannot connect to database, busy or configuration error?
  • 040: error accessing the database, is W@S installed at all?
  • 050: version mismatch, update to new version necessary
  • 060: magic_quotes_sybase is On
  • 070: there is no (default) node available in this (default) area
  • 080: there is no area available
  • 090: there is no valid theme available
The condition code is numeric because it is easier to report for non-English speaking users than a complicated English sentence. (The language files are not yet loaded when error_exit() is called).

  • return: this function never returns
  • todo: do we really want to 'leak' a link to the main site?
  • uses: WAS_VERSION - indicate internal version in 'cryptic' message
  • uses: $CFG
void error_exit (string $bare_condition_code, [string $page_title = 'Fatal Error'])
  • string $bare_condition_code: the bare condition code to report
  • string $page_title: the title to show in the generated HTML-page
initialise (line 42)

initialise the program, setup database, read configuration, etc.

void initialise ()
was_version_check (line 223)

check version of PHP-files against version stored in database

this checks the main WAS_VERSION (of files) against $CFG->version (database). if all is well, we return TRUE indicating both version numbers match. If there is a discrepancy it is logged and depending on parameter $exit_on_error we either exit alltogether OR we return FALSE to indicate the version mismatch.

Typical use is to call this routine near the start as follows (e.g. in main_index.php or main_file.php):

    ... initialise(); was_version_check(); // Still here? Then version is OK ...

This forces an exit for the interfaces at the 'visitor' side. For the webmaster it is different: even if the versions do not match, we want to be able to login and do something about it via some sort of upgrade routine, e.g:

    ... initialise(); if (!was_version_check(FALSE)) {   do_upgrade(); } else {   do_regular_admin(); } ...

  • return: TRUE if versions match, FALSE if mismatch and not $exit_on_error, no return at all otherwise
bool|void was_version_check ([bool $exit_on_error = TRUE])
  • bool $exit_on_error: if TRUE, this routine only returns if versions match, if FALSE a mismatch is fatal

Documentation generated on Wed, 11 May 2011 23:45:16 +0200 by phpDocumentor 1.4.0