phalcon/cphalcon · error · Phalcon\Config\Exceptions\CannotLoadConfigFile

Configuration file {fileName} cannot be loaded

Error message

Configuration file {fileName} cannot be loaded

What it means

Config\Adapter\Ini calls PHP's parse_ini_file(); when that returns false — the file cannot be read because it is missing or unreadable — CannotLoadConfigFile is thrown with the file's basename. The constructor does not pre-check existence, so any unreadable path lands here.

Source

Thrown at phalcon/Config/Adapter/Ini.zep:80

    use IniTrait;

    /**
     * Ini constructor.
     *
     * @param string $filePath
     * @param int    $mode
     *
     * @throws Exception
     */
    public function __construct(string filePath, int mode = 1)
    {
        var directives, iniConfig, lastValue, path, section, sections;
        array config;

        let iniConfig = this->phpParseIniFile(filePath, true, mode);

        if unlikely iniConfig === false {
            throw new CannotLoadConfigFile(basename(filePath));
        }

        let config = [];

        for section, directives in iniConfig {
            if typeof directives === "array" {
                let sections = [];

                for path, lastValue in directives {
                    let sections[] = this->parseIniString(
                        (string) path,
                        lastValue
                    );
                }

                if !empty sections {
                    let config[section] = call_user_func_array(
                        "array_replace_recursive",

View on GitHub (pinned to b7419de9cd)

Solutions

  1. Check is_file() and is_readable() before constructing the adapter
  2. Build absolute paths from __DIR__ / dirname(__DIR__)
  3. Ensure the ini file ships with the deploy artifact and is readable by the web/CLI user

Example fix

// before
$config = new \Phalcon\Config\Adapter\Ini('config/app.ini');

// after
$path = dirname(__DIR__) . '/config/app.ini';
if (!is_readable($path)) {
    throw new RuntimeException('Missing config file: ' . $path);
}
$config = new \Phalcon\Config\Adapter\Ini($path);
Defensive patterns

Strategy: validation

Validate before calling

$path = dirname(__DIR__) . '/config/app.ini';
if (!is_file($path) || !is_readable($path)) {
    throw new RuntimeException('Config file missing or unreadable: ' . $path);
}
$config = new \Phalcon\Config\Adapter\Ini($path);

Try / catch

try {
    $config = new \Phalcon\Config\Adapter\Ini($path);
} catch (\Phalcon\Config\Adapter\Ini\Exception\CannotLoadConfigFile $e) {
    // Message has the basename; report the full path for the operator
    throw new RuntimeException('Failed to load ini config: ' . $path, 0, $e);
}

Prevention

When it happens

Trigger: new Ini('app/config/settings.ini') where the file does not exist, the relative path resolves from the wrong cwd, or the file lacks read permission for the runtime user.

Common situations: Environment-specific ini files absent on a new machine; cron/systemd running the script from another directory so relative paths break; permission changes after deploying as a different user.

Related errors


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/f174dfde343d4f6f. Report an issue: GitHub.