note 83557 added to function.microtime

From: Date: Sun, 01 Jun 2008 02:10:49 +0000
Subject: note 83557 added to function.microtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-140036@lists.php.net to get a copy of this message
Here is a code that prints time taken by each step in a simple mySQL query. <?php function connect_database() { $link = mysql_connect('www.mywebsite.com', 'db_local', 'password'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('db_local'); } function disconnect_database() { mysql_close(); } function get_table() { $sttime = microtime(true); connect_database(); $timediff = round((microtime(true) - $sttime)*1000, 2); print "Connect: \t\t{$timediff} ms\n"; $query1 = "SELECT * FROM categories "; $sttime = microtime(true); $table = mysql_query($query1); $timediff = round((microtime(true) - $sttime)*1000, 2); print "Query: \t\t{$timediff} ms\n"; $sttime = microtime(true); disconnect_database(); $timediff = round((microtime(true) - $sttime)*1000, 2); print "Disconnect: \t{$timediff} ms\n"; return $table; } $sttime = microtime(true); get_table(); $timediff = round((microtime(true) - $sttime)*1000, 2); print "Total: \t\t{$timediff} ms\n"; /* ---------OUTPUT--------- Connect: 82.82 ms Query: 14.55 ms Disconnect: 0.09 ms Total: 97.65 ms */ ?> ---- Server IP: 208.69.120.35 Probable Submitter: 76.31.207.223 ---- Manual Page -- http://www.php.net/manual/en/function.microtime.php Edit -- https://master.php.net/note/edit/83557 Del: integrated -- https://master.php.net/note/delete/83557/integrated Del: useless -- https://master.php.net/note/delete/83557/useless Del: bad code -- https://master.php.net/note/delete/83557/bad+code Del: spam -- https://master.php.net/note/delete/83557/spam Del: non-english -- https://master.php.net/note/delete/83557/non-english Del: in docs -- https://master.php.net/note/delete/83557/in+docs Del: other reasons-- https://master.php.net/note/delete/83557 Reject -- https://master.php.net/note/reject/83557 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140036) next »