PHP - defining constants versus using config.ini
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 to share
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 to share