Files
computer-playbook/roles/web-app-moodle/files/build/config.php
kevinveenbirkenbachandClaude Opus 5.5 3e7bf106a3 fix(web-app-moodle): keep the component cache in debug deployments
config.php set `$CFG->debug = 32767` whenever MODE_DEBUG was true, as
the development and CI inventories set it. Moodle 5.3's
`core_component::is_developer()` treats any debug bit defined in
config.php as developer mode, so `init()` skipped
`$CFG->cachedir/core_component.php` and ran `fill_all_caches()` on
every PHP request: a walk over every plugin directory and every
`classes/` tree. The autoload in setup.php triggers it before the
ABORT_AFTER_CONFIG return, so even font.php and requirejs.php paid it.

On local disk the walk is cheap. In swarm the code tree is an NFS4
mount, and the walk turns into GETATTR round trips: main run
39494396920 served `/theme/font.php` in no less than 1.6 s and
`/lib/requirejs.php` in no less than 2.0 s, the five FPM workers per
replica queued, and the CSP check timed out loading the academy page
after 20 s on both Moodle swarm jobs.

Write `debug` and `debugdisplay` into the site config with
`admin/cli/cfg.php` instead, on every deploy and as integers (32767/1
in debug deployments, 0/0 otherwise). `is_developer()` reads only
values defined in config.php, so the component cache is honoured,
while `setup.php` still applies the stored debug level once the
database is up. The assignments leave config.php entirely, because
cfg.php refuses to change a name config.php defines, and
MOODLE_DEBUG leaves env.j2 with them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 12:06:59 +02:00

55 lines
1.9 KiB
PHP

<?php
// nocheck: mirrored-unit-test - env-driven Moodle configuration; the file assigns globals and calls Moodle's setup.php, it exposes no unit
// Env-driven Moodle config. Single source of truth for defaults is
// env.j2 (rendered by Ansible into .env/env). All MOODLE_* env vars
// MUST be set; missing values fail fast.
// See docs/requirements/015-moodle-self-built.md.
function moodle_env(string $name): string {
$v = getenv($name);
if ($v === false || $v === '') {
throw new RuntimeException("Required env var {$name} is not set");
}
return $v;
}
function moodle_env_bool(string $name): bool {
return filter_var(moodle_env($name), FILTER_VALIDATE_BOOLEAN);
}
unset($CFG);
global $CFG;
$CFG = new stdClass();
$CFG->dbtype = moodle_env('MOODLE_DB_TYPE');
$CFG->dblibrary = 'native';
$CFG->dbhost = moodle_env('MOODLE_DB_HOST');
$CFG->dbname = moodle_env('MOODLE_DB_NAME');
$CFG->dbuser = moodle_env('MOODLE_DB_USER');
$CFG->dbpass = moodle_env('MOODLE_DB_PASS');
$CFG->prefix = moodle_env('MOODLE_DB_PREFIX');
$CFG->dboptions = array(
'dbpersist' => 0,
'dbport' => moodle_env('MOODLE_DB_PORT'),
'dbsocket' => '',
'dbcollation' => 'utf8mb4_unicode_ci',
);
$CFG->wwwroot = moodle_env('MOODLE_WWWROOT');
$CFG->dataroot = moodle_env('MOODLE_DATAROOT');
$CFG->localcachedir = moodle_env('MOODLE_LOCALCACHEDIR');
$CFG->admin = 'admin';
$CFG->directorypermissions = 02770;
$CFG->routerconfigured = true;
$CFG->reverseproxy = moodle_env_bool('MOODLE_REVERSEPROXY');
$CFG->sslproxy = moodle_env_bool('MOODLE_SSLPROXY');
$_moodle_internal_host = moodle_env('MOODLE_INTERNAL_HOST');
if (explode(':', $_SERVER['HTTP_HOST'] ?? '', 2)[0] === $_moodle_internal_host) {
$_SERVER['HTTP_HOST'] = parse_url($CFG->wwwroot, PHP_URL_HOST);
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
}
require_once(__DIR__ . '/lib/setup.php');