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.

Page generated in 0.25954 seconds with 15 queries ?

Discussion in 'PHP' started by GloBleeOne, May 9, 2008.

  1. #1
    How is it possible to show the following at the footer of the site?
    SEMrush
    Page generated in 0.25954 seconds with 15 queries

    Would be interesting to see those stats while trying to speed things up
     
    GloBleeOne, May 9, 2008 IP
    SEMrush
  2. TeraTask

    TeraTask Peon

    Messages:
    37
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well, for queries, you have to count them. For time, at the top of your script put
    
    $page_generated_start_time = microtime();
    
    PHP:
    Then, where you want to display the actual number of seconds, put
    
    echo ((microtime() - $page_generated_start_time)*1000).'<br />';
    
    PHP:
     
    TeraTask, May 9, 2008 IP
  3. GloBleeOne

    GloBleeOne Peon

    Messages:
    286
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have found this code, but that does not do the mysql part.

    /* This part of the script goes at the top of your page */
    <?php
    
    $starttime = explode(' ', microtime());
    $starttime = $starttime[1] + $starttime[0];
    
    ?>
    
    
    /* This part of the script goes where you want load time to be displayed */
    <?php
    
    $mtime = explode(' ', microtime());
    $totaltime = $mtime[0] + $mtime[1] - $starttime;
    printf('Page loaded in %.3f seconds.', $totaltime);
    
    ?>
    Code (markup):
     
    GloBleeOne, May 9, 2008 IP
  4. TeraTask

    TeraTask Peon

    Messages:
    37
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Oh, I forgot about the microtime format. Change my code to

    
    $page_generated_start_time = microtime(true);
    
    PHP:
    and
    
    echo ((microtime(true) - $page_generated_start_time)*1000).'<br />';
    
    PHP:
    Again, for queries, you simply have to count them (say wrapping queries in a function or class and keeping a counter).
     
    TeraTask, May 9, 2008 IP
  5. GloBleeOne

    GloBleeOne Peon

    Messages:
    286
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I have now got the following:

    This page was generated in 0.9082 seconds

    But I do not understand about the queries part - totally lost there.
     
    GloBleeOne, May 9, 2008 IP
  6. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #6
    It all depends on how your handle your database queries. For example if your just using mysql_query() when executing queries after than line just add a simple $queries++; (set $queries to 0 at the top or something) and at the bottom of the page echo that variable. That will work but it's not a very good way to do it.

    If your using some kind of database class within the class add something like public $total_queries in the top where the class properties are defined and then in the method which handles queries add within that $this->total_queries++. Then at the end you can just echo the property in the class with the total queries, eg echo $database->total_queries;.

    Please note though that your database class if you have one may already could the total queries, and if in that case just echo that variable.
     
    chopsticks, May 9, 2008 IP
  7. GloBleeOne

    GloBleeOne Peon

    Messages:
    286
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hmm, sorry for sounding a bit dumb, but still lost.
     
    GloBleeOne, May 9, 2008 IP
  8. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #8
    How do you do your queries to the DB?

    Do you just use the standard mysql_query function? (or similar with other database types) or do you use a class to do your queries, eg $database_layer->query()?

    If so whats the name of the class you use?
     
    chopsticks, May 9, 2008 IP
    TeraTask likes this.
  9. J.T.D.

    J.T.D. Peon

    Messages:
    86
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Ok, here's a easier solution. Do you use a database for your website? If so, tell us how you 'talk' or query it. Look for anything that says 'query' in your website code, and post the entire line.

    - JTD
     
    J.T.D., May 10, 2008 IP