Martin Konecny
Martin Konecny

Reputation: 59601

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?

Upvotes: 1

Views: 160

Answers (3)

mario
mario

Reputation: 145482

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.

Upvotes: 0

Justin Ethier
Justin Ethier

Reputation: 134157

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.

Upvotes: 1

Your Common Sense
Your Common Sense

Reputation: 157870

it seems or you have profiled your app and found that this include is the worst bottleneck?

Upvotes: 3

Related Questions