The scripts were tested on Linux 3.8.4, PHP 5.4.12, MySQL 5.5.30.
First script, test_mysql.php
<?php //-----Start Timer-------------------------------------------------// $time = microtime(); $time = explode(" ", $time); $time = $time[1] + $time[0]; $top = $time; //-----Start Timer-------------------------------------------------// for($j=0;$j<1000;$j++) { $link = mysql_connect($host,$user,$password) or die('Error in Server information'); mysql_select_db($db,$link) or die('Can not Select Databasse'); $query="select * from com_list where field1='value1';"; $res = mysql_query($query); //1 is ok if (!$res) { die('Invalid query: ' . mysql_error()); } while($row = mysql_fetch_array($res)){ $i++; } mysql_free_result($res); mysql_close($link); } echo "Total lines :".$i; //-----End Timer-------------------------------------------------// $time = microtime(); $time = explode(" ", $time); $time = $time[1] + $time[0]; $bottom = $time; //-----End Timer-------------------------------------------------// $loadtime = ($bottom-$top); echo ("<br> <br>This page generated in $loadtime seconds"); ?>Second script, test_mysqli.php
<?php //-----Start Timer-------------------------------------------------// $time = microtime(); $time = explode(" ", $time); $time = $time[1] + $time[0]; $top = $time; //-----Start Timer-------------------------------------------------// for($j=0;$j<1000;$j++) { $link = mysqli_connect($host,$user,$password,$db) or die('Error in Server information'); $query="select * from com_list where field1='value1';"; $res = mysqli_query($link,$query); //1 is ok if (!$res) { die('Invalid query: ' . mysql_error()); } while($row = mysqli_fetch_array($res)){ $i++; } mysqli_free_result($res); mysqli_close($link); } echo "Total lines :".$i; //-----End Timer-------------------------------------------------// $time = microtime(); $time = explode(" ", $time); $time = $time[1] + $time[0]; $bottom = $time; //-----End Timer-------------------------------------------------// $loadtime = ($bottom-$top); echo ("<br> <br>This page generated in $loadtime seconds"); ?>
No comments :
Post a Comment