How can configuration loading be optimized in PHP applications for better performance?

To optimize configuration loading in PHP applications for better performance, one approach is to cache the configuration data after loading it once. This can reduce the overhead of reading and parsing configuration files on each request.

// Load configuration data
function loadConfig() {
    $config = []; // Load configuration data from file or database
    return $config;
}

// Get configuration data, either from cache or load it
function getConfig() {
    $config = apc_fetch('app_config');
    
    if (!$config) {
        $config = loadConfig();
        apc_store('app_config', $config);
    }
    
    return $config;
}

// Example of using cached configuration data
$config = getConfig();
echo $config['database']['host'];