PHP - defining constants versus using config.ini

Performance wise, I was wondering which method of defining constants / settings is better?

Using config.ini file via Zend_Config_Ini class or just defining a series of php constants?

+2


source to share


2 answers


Defining PHP constants is faster.

Why:



  • A persistent file should not be parsed by your application and converted to PHP variables
  • If unchanged the PHP constants file will be cached by bytecode if you have APC installed
  • Constants do not change by default and have better performance than arrays or plain old variables because their size and type do not change.
+3


source


Since it requires a call to parse_ini_file () to use .ini files (and thus reads the file on disk), it will be trivially slower than the inline defining constants. Although, if you define your constants in a separate PHP file and include () it will probably end up the same thing.



However, I generally recommend using .ini files because it is more maintainable and easier to deploy.

0


source







All Articles