Jump to content


PHP code request


  • Please log in to reply
24 replies to this topic

#1 Sphere

Sphere

    The moth next to my brain is Bart, say hi to him if you like

  • Sponsor
  • PipPipPipPipPip
  • 2,355 posts
  • Location:*tap* Behind ya!
  • Interests:I'm a Dutchy, that means I'm not a German (which doesn't sound/look the same to me!) also, being a Dutchy means I'm an idiot... sort off!

    And I def. need to get a real life again... I'm bored with my current life, ideas can be pm'd to me!
  • Country:Dutchyland

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?

#2 brewin

brewin

    Victory is mine!

  • Administrator
  • PipPipPipPipPip
  • 1,262 posts
  • Location:Missouri
  • Interests:Anything interesting.
  • Country:USA

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

<?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 Sphere

Sphere

    The moth next to my brain is Bart, say hi to him if you like

  • Sponsor
  • PipPipPipPipPip
  • 2,355 posts
  • Location:*tap* Behind ya!
  • Interests:I'm a Dutchy, that means I'm not a German (which doesn't sound/look the same to me!) also, being a Dutchy means I'm an idiot... sort off!

    And I def. need to get a real life again... I'm bored with my current life, ideas can be pm'd to me!
  • Country:Dutchyland

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 :cc_surrender: )

#4 brewin

brewin

    Victory is mine!

  • Administrator
  • PipPipPipPipPip
  • 1,262 posts
  • Location:Missouri
  • Interests:Anything interesting.
  • Country:USA

Posted 22 March 2008 - 11:43 PM

Cool, looks good. :cc_surrender:

#5 Sphere

Sphere

    The moth next to my brain is Bart, say hi to him if you like

  • Sponsor
  • PipPipPipPipPip
  • 2,355 posts
  • Location:*tap* Behind ya!
  • Interests:I'm a Dutchy, that means I'm not a German (which doesn't sound/look the same to me!) also, being a Dutchy means I'm an idiot... sort off!

    And I def. need to get a real life again... I'm bored with my current life, ideas can be pm'd to me!
  • Country:Dutchyland

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.

#6 banj0

banj0

    American Idle

  • Sponsor
  • PipPipPipPipPip
  • 1,537 posts
  • Location:Detroit
  • Country:States

Posted 23 March 2008 - 06:04 PM

The Nuke software comes with code that generates this at the bottom:

Attached File  code.jpg   17.58K   9 downloads

I could dig around for it if you want.

#7 Sphere

Sphere

    The moth next to my brain is Bart, say hi to him if you like

  • Sponsor
  • PipPipPipPipPip
  • 2,355 posts
  • Location:*tap* Behind ya!
  • Interests:I'm a Dutchy, that means I'm not a German (which doesn't sound/look the same to me!) also, being a Dutchy means I'm an idiot... sort off!

    And I def. need to get a real life again... I'm bored with my current life, ideas can be pm'd to me!
  • Country:Dutchyland

Posted 23 March 2008 - 07:04 PM

I indeed am searching for something like that, my current only times. :cc_surrender:

If you find anything, please post, but don't make it your life purpose!

#8 banj0

banj0

    American Idle

  • Sponsor
  • PipPipPipPipPip
  • 1,537 posts
  • Location:Detroit
  • Country:States

Posted 23 March 2008 - 09:47 PM

Ok, no worries. I'll poke around and let you know. :cc_surrender:

#9 banj0

banj0

    American Idle

  • Sponsor
  • PipPipPipPipPip
  • 1,537 posts
  • Location:Detroit
  • Country:States

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 Sphere

Sphere

    The moth next to my brain is Bart, say hi to him if you like

  • Sponsor
  • PipPipPipPipPip
  • 2,355 posts
  • Location:*tap* Behind ya!
  • Interests:I'm a Dutchy, that means I'm not a German (which doesn't sound/look the same to me!) also, being a Dutchy means I'm an idiot... sort off!

    And I def. need to get a real life again... I'm bored with my current life, ideas can be pm'd to me!
  • Country:Dutchyland

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 :cc_surrender:

#11 banj0

banj0

    American Idle

  • Sponsor
  • PipPipPipPipPip
  • 1,537 posts
  • Location:Detroit
  • Country:States

Posted 23 March 2008 - 11:34 PM

Here's the entire file.

Attached File  footer.php   10.48K   5 downloads

#12 Sphere

Sphere

    The moth next to my brain is Bart, say hi to him if you like

  • Sponsor
  • PipPipPipPipPip
  • 2,355 posts
  • Location:*tap* Behind ya!
  • Interests:I'm a Dutchy, that means I'm not a German (which doesn't sound/look the same to me!) also, being a Dutchy means I'm an idiot... sort off!

    And I def. need to get a real life again... I'm bored with my current life, ideas can be pm'd to me!
  • Country:Dutchyland

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 :cc_surrender:

#13 banj0

banj0

    American Idle

  • Sponsor
  • PipPipPipPipPip
  • 1,537 posts
  • Location:Detroit
  • Country:States

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.

Edited by banj0, 23 March 2008 - 11:57 PM.


#14 Sphere

Sphere

    The moth next to my brain is Bart, say hi to him if you like

  • Sponsor
  • PipPipPipPipPip
  • 2,355 posts
  • Location:*tap* Behind ya!
  • Interests:I'm a Dutchy, that means I'm not a German (which doesn't sound/look the same to me!) also, being a Dutchy means I'm an idiot... sort off!

    And I def. need to get a real life again... I'm bored with my current life, ideas can be pm'd to me!
  • Country:Dutchyland

Posted 24 March 2008 - 12:05 AM

cool, well... at least I have the page-build time now :cc_surrender:

I'm currently busy classing and functioning my entire engine (which I may proudly present as my own :rofl_mini: ), which takes a while, since I suck at using classes etc.

#15 brewin

brewin

    Victory is mine!

  • Administrator
  • PipPipPipPipPip
  • 1,262 posts
  • Location:Missouri
  • Interests:Anything interesting.
  • Country:USA

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.

$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