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.

can i check with php how many queries to a database per page?

Discussion in 'PHP' started by Dirty-Rockstar, Jul 11, 2009.

  1. #1
    With all my includes and code on other pages my project is getting pretty big. I was wondering if there was some way, php or otherwise I could check how many separate queries to a database each page makes? Im rocking localhost so if cpanel can do this its not applicable at the moment but I would like to know if it is possible at all. I just want to control redundant queries and this data could help me
     
    Dirty-Rockstar, Jul 11, 2009 IP
  2. mdrobiul

    mdrobiul Peon

    Messages:
    186
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ok. it can act like a hit counter. i'm suggesting a way. every script and every query code, you have to add another query which will add 1 to your query table. mainly it will add 2, because this query is also a query which we should count. now find all queryies in your php code and add another php query operation after that which will work as counter. it will be quite easier to make report for all pages in one table rather than gernerating for seperate page(it's going to be complicate).
     
    mdrobiul, Jul 11, 2009 IP
  3. theapparatus

    theapparatus Peon

    Messages:
    2,925
    Likes Received:
    119
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Is this for a custom php script of your own or a CMS or other program?
     
    theapparatus, Jul 11, 2009 IP
  4. Dirty-Rockstar

    Dirty-Rockstar Guest

    Messages:
    252
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Custom php website(localhost at the moment). built from scratch. 2 years knowing php. Which is why this data would be awesome. For the first replier, I thought of that however that would DOUBLE the amount of queries which is not what I want to do at all. I just use, insert, update and select. That is it. I was thinking on $i++ after each query then echo that number at the bottom of each page or something.
     
    Dirty-Rockstar, Jul 11, 2009 IP
  5. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #5
    I use verbose logging and profiling during development to find bottlenecks in code and SQL queries.
     
    Social.Network, Jul 11, 2009 IP
  6. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #6
    If the database is shared, use a variable to hold the count after each query. If the database is dedicated, you might be able to use the status query, which tells you the average queries count.
     
    ThePHPMaster, Jul 11, 2009 IP
  7. Dirty-Rockstar

    Dirty-Rockstar Guest

    Messages:
    252
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    what is the difference between shared and dedicated. There is just one database I use with about 50 tables in it I never plan on having more then one database and live it is one dedicated server. im thinking that the var route will be the one i might have to take. Thank you all for your replies
     
    Dirty-Rockstar, Jul 12, 2009 IP