Re: [PHP] Includes eating up my time
- From: larry@xxxxxxxxxxxxxxxx (Larry Garfield)
- Date: Tue, 31 Jul 2007 08:59:48 -0500
On Tuesday 31 July 2007, Dave M G wrote:
PHP general list,
This is probably obvious to people who are good at PHP, but I'm
I have a PHP based CMS (content management system) built, which has
grown and become quite robust. It's now spread out over about 30 files,
and each file represents one class within the object oriented design.
Each are a couple hundred lines of code, and two or three of the most
critical classes are over a thousand lines of code.
While first building it, I didn't really anticipate quite that many
files. What I did is have a file called "includes.php", which list all
the files to be included. Then I in turn included "includes.php" at the
beginning of my "index.php" file. Every page request passes through the
"index.php" file, so that basically means every single file is included
at the start of every new page request.
Yep, that's the downside of a shared-nothing architecture. Initialization
gets slower.
Possible solutions include:
- If you're using all classes, use PHP 5's __autoload() or better still
spl_autoload_register() to load classes on demand instead of all at once.
- Refactor your code to conditionally include code only when needed. E.g.,
you probably only need one page handler loaded per page request. I'm in the
process of doing that for Drupal right now and the savings are quite
substantial.
- Op code cache. This is exactly where an op code cache will get you the
biggest win, by saving you the loading and parsing time.
- Page caching. To do page caching best, you should have the system do a
partial bootstrap, check to see if it can serve a page from the cache, do so
if it can, and if it can't only then finish loading the rest of the system.
That way you skip most of the loading process on cached requests.
- Some combination of the above. I'd do the op code cache last, as that's a
sure-fire easy win while the others take effort. So do those first, and then
whatever's left you can throw an op code cache at for an extra boost.
--
Larry Garfield AIM: LOLG42
larry@xxxxxxxxxxxxxxxx ICQ: 6817012
"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
.
- References:
- Includes eating up my time
- From: Dave M G
- Includes eating up my time
- Prev by Date: RE: [PHP] Array difficulty
- Next by Date: Unexpected values in PHP array
- Previous by thread: Re: Includes eating up my time
- Next by thread: Flash 8 UI controls
- Index(es):