How is it possible to show the following at the footer of the site? Page generated in 0.25954 seconds with 15 queries Would be interesting to see those stats while trying to speed things up
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:
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):
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).
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.
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.
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?
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