Page 1 of 1

PHP's include() performance & bottlenecks?

Posted: Wed Oct 01, 2003 5:08 am
by KimmoK
Hello all,

I got a bit of a situation with using PHP includes on my site. Let me explain the whole deal in bit more detail.

I'm generating some PHP-pages on the fly from several included files, all of which have PHP code and some MySQL queries in them. This is needed because the content is customized for each user separately according to session variables set on their browsers. I've got the MySQL queries optimized very well, and I'm using indexes if, for example, where-clauses are used. The database connection itself is opened up at the start of the page. All important variables such as user's ID are carried within $_SESSION.

My concern is with PHP's include() and the bottleneck it can create by reading from the drive. What alternatives could you suggest to do deal with this situation? Would it be lighter to store all the template-files in a table, parse the templates, and then echo out the output?

I've also installed PHP-Accelerator today to help with caching the created content, but I'm not sure if that's actually useful in this situation because the content updates continually.

Thanks in advance!

Posted: Wed Oct 01, 2003 4:00 pm
by adamk
The only way to fix that would be to get a faster hard drive, more memory, and a faster CPU. The faster hard drive is probably what would help the most. A HDD that spins at 5,400RPM is a LOT slower than one that spins at 10,000RPM. By a lot I mean like a tricycle at top speed racing a Jet at top speed.

Caching would be one way to go, but it kind of contradicts itself. What if you make a change to the file that is cached? Sure, the caching program/script checks it's cache against the actual file, but wouldn't that defeat the purpose of trying not to open the file? If you open the file for comparison, why wouldn't you just read the file's contents to use, since they would be the most recent?

These are just my thoughts and could be flawed. If you find any holes, let me know!

Posted: Wed Oct 01, 2003 4:27 pm
by jason
Include optimization tips...

Don't use the *_once() functions. Correctly manage your file includes.

Correctly set and use your include_path. If most of your includes are including files in a certain directory, make that directory the first path in the include_path

If you can, set your include_path as close to the root directory as possible. /phpinc would be good, / would be the best (though, not realistic). This will usually spead up includes.

Generally, includes will not be a major bottleneck before your Database. Optimizing there first is important.

Posted: Wed Oct 01, 2003 7:04 pm
by JAM
According to an article in the PHP community (I tried, but I cant find it again) a couple of admins discussing used Zend's caching software with on-the-fly page creations without any problems (from what I made from it).

I just wanted to mention it, as I personally have no experience with it myself. Zend themselves perhaps has something interesting in their whitepapers.