Configuration file for PHP server script
Right now I have a very high volume of requests coming to my webserver which execute a PHP CGI script.
Every one of these scripts opens up a config file that I have created to load options of how the script should run.
Doing a file I/O operation everytime a request comes in 开发者_开发百科seems very resource intensive to me. I'm not too familiar with the advanced features of PHP, are there any alternatives to achieve what I'm doing?
it seems or you have profiled your app and found that this include is the worst bottleneck?
Here are some ideas for you:
You could put the data in session, which can store data for each user.
Alternatively you could cache parameters in memory using a tool such as memcached.
Alternatively you could place configuration options in a PHP file instead of in a config file. This would simplify the parsing, and would also allow for caching if you are using a tool such as eAccelerator that automatically caches compiled PHP scripts.
In any case, before making optimizations you really should profile your application to identify the actual bottlenecks.
Col.Shrapnel is right. A single file access isn't really expensive. Remember you have a file access for EVERY .php script your application is composed of.
If your configuration file is in parse_ini_file() format, worry not. Parsing it is even faster than a PHP script. However, if you are using an opcode cache, you could turn your configuration script into a PHP array / data script. This way the disk I/O gets redundant, as your opcode cache keeps Zend bytecode in memory.
精彩评论