views:

824

answers:

2

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

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

+1  A: 

Since using .ini files requires a call to parse_ini_file() (and thus reads a file on disk) it will be trivially slower than defining constants inline. Though if you define your constants in a seperate PHP file and include() it would probably come to the same thing.

However, I would usually recommend using .ini files because it is more maintainable and makes deployments simpler.

ctford
A: 

Defining PHP constants is faster.

Why:

  1. The constant file needs not to be parsed by your application and converted into PHP variables
  2. If not changed the PHP constant file will be bytecode cached if you have APC installed
  3. Constants are per default unchangeble, and have a better perfomance than arrays or plain old variables since their size and type doesn't change , ever.
Nikola Stjelja