3

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?

2 Answers 2

4

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.
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.