faqts : Computers : Programming : Languages : PHP : Common Problems : Tips and Tricks

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

20 of 26 people (77%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How can I improve the performance of my very large site?
I have a lot of include()'d code, how can I improve performance?

Aug 10th, 1999 22:57
Nathan Wallace, Jacob Stetser


Try using _conditional includes_ and only include what you need for
any particular page. I did this and speeded up a script of mine that
was running into about 2-3,000 lines of code.. it was usually running
between 1-4 seconds per page, and now it runs between .1-.9 sec per
page. I instituted a caching system and pages that are cached take
about 2-3 THOUSANDTHS of a second per page PHP execution time! (I
still use PHP to determine whether to serve a cached page or a real
page, but the script is only about 150 lines total before I call an
exit(); if it serves a cached page.

I don't have any real world testing of how this affects server load,
but I have a feeling that PHP does better the less code you give it
at a time, and that caching pages, if it can be done, can make
a script incredibly light when it comes to server load.

Example of conditional include

    if($action=="buystock") {
        include("./includes/buystock.inc");
    } elseif(....) {
        include("....");
    } etc...