A great way to store application config, but unfortunately a better way of slowing down the application. Parsing and accessing ini files is somewhat of a heavy process, here is a webgrind output using a stripped down version of the Zend Framework Zend_Config_Ini class:

The main reason for the long processing time of these functions is that they are riddled with recursive functions, which quickly add up. Unfortunately there is little that can be done about the processing time, but there are other possibilities.

The first and most obvious optimisation is to cache the parsed config file, completely eliminating the processing overhead. By default all config files are parsed and saved in a serialised state in the cache directory, this can be switched for Memcache and possibly SHM at a later stage.

The second optimisation that provides a nice speed boost is to change the way the data is stored, multiple calls to the __get magic method soon start to add up and become a bottleneck. For this reason I changed the big array of objects into a simple array structure, leaving the __get magic method so that the top level configuration data can still be accessed in an object format.

For example to access a field called param within session configuration data from the parsed config in LiteMVC we can do the following:

$config = new LiteMVC\App\Config\Ini(‘config.ini’);
$sessionConfig = $config->session;
$sessionParam = $sessionConfig['param'];

This maintains a nice level of usability while almost completely eliminating data access processing overheads. As often using Zend Framework it’s necessary to use the toArray method (another recursive function) this is also completely eliminated as data is already in array form.

Here is a webgrind output showing the new ini parser with file caching, taking just 367 microseconds to load the configuration:

Share