Performance/caching of PHP classes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
edwardaux
Forum Newbie
Posts: 6
Joined: Thu Sep 01, 2005 5:55 pm

Performance/caching of PHP classes

Post by edwardaux »

I am new to PHP (although not inexperienced in web development) and am curious as to how the Zend engine handles the caching of previously interpreted PHP code.

I have developed a new web application that is fairly heavily reliant on PHP classes and has a reasonably complicated object model. In an environment where my PHP interpreter is loaded as a module (ie. not CGI), would I be right in assuming that the class definitions are interpreted just once and then cached internally within the Zend engine (assuming I use require_once statements)?

The reason I ask is that I don't like the thought that *every* time a user requests a page, the interpreter may have to include, validate and interpret 40 or 50 PHP files (containing many lines of PHP code).

Are there any papers on how the zend engine handles this? My performance is pretty good at the moment... I just want to make sure I understand how it works in the future if the workload increases.

Many thanks.
Craig
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

data is cached for a single page request only (unless you are using streamed or shared memory systems). This changes as well when you use a Zend-engine caching system.
edwardaux
Forum Newbie
Posts: 6
Joined: Thu Sep 01, 2005 5:55 pm

Post by edwardaux »

Thanks for the quick reply. When you say a "Zend-engine caching system", I presume you mean something like Turck MMCache for PHP or PHP Accelerator [both found from a quick google search]?

If I elected to stay with the vanilla engine, I'm curious as to whether there is anything I can do (or not do) in terms of my code management to assist in giving good performance. For example, does flattening the class hierarchy make any difference? Should I put all my class definitions in one big file, or does putting each class definition in its own file help? (Gut-feel tells me that if I do this, at least I can selectively use the require statement and so reduce the number of classes that need to be interpreted for each page)

As I said, my current performance is good so I am not too worried. However, I figure that if making some basic design decisions early on will make/break my application later, then now is the time to make them. Are there any must-read publications/whitepapers that I should read with regard to PHP performance? Thanks again for your help.

Craig
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Breaking classes down to their own files, and selectively including/requiring them will help performance. If you are looking to further increase performance try a bytecode cache, but before trying the bytecode cache make sure everything is optomized to it's full potential.
there are free solutions as well as non-free ones.
Post Reply