What happens when you require config.php

Jump to: navigation, search
Notice: Moodle Docs will be switched to read-only mode starting on Tuesday 17 October 14:00 UTC for server maintenance. The estimated read-only period should not take more than 24 hours.

Most scripts in Moodle start with the line

require_once(__DIR__. '/../../config.php');

with an appropriate number of '../'s. This achieves two main things

  1. It loads all the Moodle core library code.
  2. In initialises a lot of things like the database connection, the session, the current course, theme and language.

The most reliable way to find out exactly what is going on is to actually go and read the code for config.php, lib/setup.php and the library functions they call. However, the following diagram gives an overview of some of the most important points.

Moodle startup.png

That diagram was drawn looking at the Moodle 2.0 dev code, but it should be similar for most recent version. It is about to change a lot in 2.0 dev over the next few months.

Here is the same image as a .dia file that can be edited with the open source drawing program of the same name: File:Moodle startup.dia.

See also