Home Account

parse ini file cached with APC

29-Dec-2011 14:45:37 dennis

Tags: php scripts-and-functions apc

Normally APC will not cache ini files with parse_ini_file Therefor I made this function in order to cache all ini files. This means that ini files are not read by every request, but only read once and keept in memory: This will make your web application faster.

    function parse_ini_file_ext ($file, $sections = null) {
        ob_start();
        include $file;
        $str = ob_get_contents();
        ob_end_clean();
        return parse_ini_string($str, $sections);
    }

I have added this function to my coscms framework as this uses PHP ini files for all configuration. And it all started with a question on stackoverflow were I gave the above answer.