PHP's include() performance & bottlenecks?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
KimmoK
Forum Newbie
Posts: 1
Joined: Wed Oct 01, 2003 5:08 am

PHP's include() performance & bottlenecks?

Post 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!
adamk
Forum Newbie
Posts: 4
Joined: Tue Sep 30, 2003 10:59 pm
Location: Granbury, TX
Contact:

Post 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!
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post 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.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
Post Reply