print timestamp

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
johnhelen
Forum Commoner
Posts: 45
Joined: Mon Feb 19, 2007 9:17 pm

print timestamp

Post by johnhelen »

Hello

In a php script, I have a query to select a record from a database. I really want to know how long this query will take

So I want to print time stamp before and after this query (in miliseconds). However, php cannot print a timestamp value

Could you please help

regards
john
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PHP has time stamps in various forms internally. I can't see how PHP "cannot print" one.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

microtime() is what you're afrer:

Code: Select all

$time_start = microtime(true);

// query here
MySQL_query("SELECT * FROM table WHERE `bob`='yourUncle'");

$time_end = microtime(true);
$time = $time_end - $time_start;

echo "Query took $time seconds\n";
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Everah | Moved to PHP code.

If you haven't already clicked on the microtime() function link, you should. Right up toward the top of the page is an example of doing exactly what you want to do.
Post Reply