1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP - speed up page generation time.

Discussion in 'PHP' started by Lucky Bastard, Mar 30, 2005.

  1. #1
    The page in question contains LOTS (too many for my liking) SQL queries (it is a highly modified oscom. site, mod rewrite etc) I have JUST turned SQL Query caching on.

    Using fairly common techniques to determine page generation time -
    Get the time at the VERY beginning of a PHP script
    Get the time at the VERY end of a php script
    Work out the diff.

    My sites home page has page generation times of about .150 seconds. This is under fairly low load. Is this figure in itself alarming or reassuring of...?


    Secondly: I was thinking about cutting the number of queries down (even though now I am using query caching) as I am wanting to optimise further.

    I was thinking of storing in an array at the beginning of every page request the most required fields in the products (2000+ rows) and categories (100+ rows) tables (most common tables required throughout most pages). These couple of queries would then be stored in the query cache for later use on other pages/by other users etc.
    Then during the rest of the page generation/processing, rather than my MANY queries accessing the query cache I would just query the couple of stored arrays (products, categories) and query out of the array the required data at that particular point in time. This would happen many times over in the page.

    So rather than having multiple (many multiple) hits on the DB or query cache I would be parsing these decent size (large??) arrays (2000+ records max) multiple (many multiple) times in the one page.

    Would such be faster than accessing the query cache or would it be negligible and thus probably not worth the time in re-coding and accessing the arrays? I know in doing so I could probably reduce the number of hits on the query (cache) by up to 80-90%.

    Hope this all makes sense.
     
    Lucky Bastard, Mar 30, 2005 IP
  2. palespyder

    palespyder Psycho Ninja

    Messages:
    1,254
    Likes Received:
    98
    Best Answers:
    0
    Trophy Points:
    168
    #2
    Do you really need all that information on every page though? It seems to use a bit more memory then required by any web application I have ever seen.
     
    palespyder, Mar 30, 2005 IP
  3. davedx

    davedx Peon

    Messages:
    429
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You might want to look into doing SQL joins - you can usually combine two or more queries into one that way. Did that with one of my sites and cut down the queries dramatically.

    0.15s is ok for a DB intensive page though I'd say. Are you on a dedicated server, DB host, etc?
     
    davedx, Mar 30, 2005 IP
  4. Lucky Bastard

    Lucky Bastard Peon

    Messages:
    406
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    On a dedicated server (for me), I've got a couple of other sites running on it though - all fairly low intensity.

    Pale, agree wouldn't need to do the query I mentioned on every page, but would only do it on the pages that I required it.
     
    Lucky Bastard, Mar 30, 2005 IP