

PHP code request
Started by
Sphere
, Mar 22 2008 07:52 PM
24 replies to this topic
#1
Posted 22 March 2008 - 07:52 PM
Hey everybody,
I'm looking for a solid good working SQL query time application in PHP. Currently, I have one that doesn't work the way I want, it's slow, gives me a result of 8 behind the . etc.
I want a simple one that just gives me a time calculation on how long the SQL query took.
Anyone got something usefull?
I'm looking for a solid good working SQL query time application in PHP. Currently, I have one that doesn't work the way I want, it's slow, gives me a result of 8 behind the . etc.
I want a simple one that just gives me a time calculation on how long the SQL query took.
Anyone got something usefull?
#2
Posted 22 March 2008 - 08:44 PM
You can use microtime. Subtract the start time from the end time and you'll get the time it took to execute the script.
http://us.php.net/ma...n.microtime.php
Is that what you're looking for?
http://us.php.net/ma...n.microtime.php
<?php $time_start = microtime(true); // your script goes here $time_end = microtime(true); $time = $time_end - $time_start; echo "Execution took $time seconds\n"; ?>
Is that what you're looking for?
#3
Posted 22 March 2008 - 10:30 PM
That one rules!
I was working with time, but it really didn't get me any usefull result!
Thanks (and I need to search better)
*not advertise, but saying anyway*
To see the result, see the bottom of my website! (sig-image-clicky
)
I was working with time, but it really didn't get me any usefull result!
Thanks (and I need to search better)
*not advertise, but saying anyway*
To see the result, see the bottom of my website! (sig-image-clicky

#4
Posted 22 March 2008 - 11:43 PM
Cool, looks good.

#5
Posted 23 March 2008 - 12:35 AM
Yeh, I'm sorry if you've encountered errors last couple of hours. I've been editing code like @#$%^&, moving all SQL queries into a function, so it'd be safer and offcourse, faster.
#7
Posted 23 March 2008 - 07:04 PM
I indeed am searching for something like that, my current only times. 
If you find anything, please post, but don't make it your life purpose!

If you find anything, please post, but don't make it your life purpose!
#8
Posted 23 March 2008 - 09:47 PM
Ok, no worries. I'll poke around and let you know.

#9
Posted 23 March 2008 - 09:54 PM
My site's footer.php contains these for that pic above:
} $total_time = (get_microtime() - $start_time); $total_time = '<span class="copyright">[ '._PAGEGENERATION." ".substr($total_time,0,4)." "._SECONDS; if ($start_mem > 0) { $total_mem = memory_get_usage()-$start_mem; $total_time .= ' | Memory Usage: '.(($total_mem >= 1048576) ? round((round($total_mem / 1048576 * 100) / 100), 2).' MB' : (($total_mem >= 1024) ? round((round($total_mem / 1024 * 100) / 100), 2).' KB' : $total_mem.' Bytes')); } /*****[BEGIN]****************************************** [ Other: Queries Count v2.0.1 ] ******************************************************/ if($queries_count) { $total_time .= ' | DB Queries: ' . $db->num_queries; } /*****[END]******************************************** [ Other: Queries Count v2.0.1 ] ******************************************************/ $total_time .= ' ]'; $total_time .= '</span><br />';
#10
Posted 23 March 2008 - 10:24 PM
do you have the class and function "num queries" with that?
It's kinda needed to make the request $db->num_queries; work
It's kinda needed to make the request $db->num_queries; work

#12
Posted 23 March 2008 - 11:37 PM
Getting everything I need to write my own "query count" would from what I see require me to completely dis-assemble PHP-NUKE.....
All that the footer does is actually parse defined functions and classes.... there's no information on how it actually gets to the result
All that the footer does is actually parse defined functions and classes.... there's no information on how it actually gets to the result

#13
Posted 23 March 2008 - 11:56 PM
Hmm. Sorry bro.
I posted your request to a Nuke forum asking for the code to add to any site. If anyone replies, I'll let ya know.
I posted your request to a Nuke forum asking for the code to add to any site. If anyone replies, I'll let ya know.
Edited by banj0, 23 March 2008 - 11:57 PM.
#14
Posted 24 March 2008 - 12:05 AM
cool, well... at least I have the page-build time now 
I'm currently busy classing and functioning my entire engine (which I may proudly present as my own
), which takes a while, since I suck at using classes etc.

I'm currently busy classing and functioning my entire engine (which I may proudly present as my own

#15
Posted 24 March 2008 - 01:40 AM
Just based on that bit of code from PHP-Nuke, you might be able to get it all to work.
The number of queries could be just an int that gets incremented every time a query is run.
And this will probably work for memory usage. I'm just guessing that $start_mem is memory usage before the script is run.
The number of queries could be just an int that gets incremented every time a query is run.
$num_queries = 0 function { // query runs here $num_queries++ } function { // another query runs here $num_queries++ } ... echo "DB Queries: " . $num_queries;
And this will probably work for memory usage. I'm just guessing that $start_mem is memory usage before the script is run.
$start_mem = memory_get_usage(); // your script goes here if ($start_mem > 0) { $total_mem = memory_get_usage() - $start_mem; echo "Memory Usage: " . (($total_mem >= 1048576) ? round((round($total_mem / 1048576 * 100) / 100), 2) . " MB" : (($total_mem >= 1024) ? round((round($total_mem / 1024 * 100) / 100), 2) . " KB" : $total_mem . " Bytes")); }
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users