Why is my php/query slow first time, but not second?

Discussion in 'PHP' started by puffyz, Mar 6, 2008.

  1. #1
    $res1=mysql_query('select id, feed_title, feed_detail, feed_image, pub_date from link_feeds where rss_id=' . $id . ' order by id desc' . $nrec . '');

    which query turns into:
    select id, feed_title, feed_detail, feed_image, pub_date from link_feeds where rss_id=249 order by id desc limit 0,8

    On first load on page I get slow time...

    after
    $res1=mysql_query('select id, feed_title, feed_detail, feed_image, pub_date from link_feeds where rss_id=' . $id . ' order by id desc' . $nrec . '');
    =
    Processed:0.393Memory:389920

    other queries, few diff stuff after, final total loading time for box
    all the way through the while($row1=mysql_fetch_assoc($res1))

    with above time is

    =
    Processed:0.395Memory:389920

    ----


    there is about 16 diff boxes so it matters...

    If you refresh the page they all load in .001...I do the query by itself always get .001 or less....

    What am I doing wrong? Thanks.
     
    puffyz, Mar 6, 2008 IP
  2. lephron

    lephron Active Member

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #2
    On any subsequent loads the php will be cached, so the php interpreter won't need to lookup all the symbols again.
     
    lephron, Mar 7, 2008 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    Judging by your previous posts, I think that the database size is what's slowing it down, assuming that this is the same one as before.
     
    jestep, Mar 7, 2008 IP
  4. puffyz

    puffyz Guest

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yes the db has about 1.2 million records, but that cant change...


    I am not sure why this query is taking 8 seconds to load. There is about a 1.2 million records in link_feeds.

    There are indexes on: with cardility
    ID PRIMARY 1193287
    rss_id INDEX 5473
    pub_date INDEX 596643
    hits INDEX 389
    titleindx INDEX 1193287
    feed_url INDEX 1193287

    EXPLAIN SELECT id, feed_title, feed_detail, feed_image, pub_date
    FROM link_feeds
    WHERE rss_id =2
    ORDER BY id DESC
    LIMIT 25
    [ Edit ] [ Skip Explain SQL ] [ Create PHP Code ]

    id select_type table type possible_keys key key_len ref rows Extra
    1 SIMPLE link_feeds ref rss_id rss_id 2 const 4105 Using where; Using filesort

    I am not sure, your help is greatly appreciated thanks! This is puzzling..
     
    puffyz, Mar 12, 2008 IP
  5. puffyz

    puffyz Guest

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    bump thanks!!!
     
    puffyz, Mar 13, 2008 IP
  6. lephron

    lephron Active Member

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #6
    puffyz I thought you said the query always takes the same time regardless? If that is the case then obviously this is a PHP issue, not a SQL one.
     
    lephron, Mar 13, 2008 IP
  7. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #7
    The database will be doing its own caching.
     
    matthewrobertbell, Mar 13, 2008 IP