tags:

views:

273

answers:

4

I know some people store settings in an .ini file and get the values with parse_ini_file() in PHP. Without running tests, I am curious about performance.

Do you know if opcode cache can cache any of this type of stuff if setting are in an ini file?

+5  A: 

I had always harboured the suspicion that parse_ini_file is dismally slow, and that storing variables in arrays in PHP files is faster. But there's this 2004 article that says otherwise:

And lastly we test storing configuration parameters in an INI file or in a PHP file as an associative array. We found that storing in an INI file and using parse_ini_file() is faster than parsing a PHP file.

I won't entirely believe this until I test it myself when I get around to it some time. But the article (and the magazine) look solid enough to be taken seriously.

Pekka
wow thats great thanks, I might do some test myself
jasondavis
If you do, I'd be very interested in the results!
Pekka
@jasondavis: I second Pekka.
Alix Axel
Did they (also) test it using something like apc? On the other hand you might not want your "configuration" file to be able to execute code.
VolkerK
A: 

You will be much faster if you dont cache the ini file. All experts can cay that this is true.

streetparade
-1 For the use of the word 'experts'
AntonioCS
A: 

The parse_ini_file built-in function is implemented in C. This makes it quite fast.

Neville Flynn
Which built-in functions are not implemented in C?
lamas
+5  A: 

According to this blog post (English Translation)

From fastest to slowest:

  1. Serialized arrays
  2. Plain PHP code
  3. INI files
  4. XML files
  5. YAML files
Crozin
+1 interesting find, also interesting to see that this benchmark also (partly) seems to favour INIs over PHP includes. Google's translation quality is superb by the way, I initially thought I was reading a original english text.
Pekka