note 15530 deleted from function.mysql-pconnect by jimw

From: Date: Fri, 07 Dec 2001 01:47:08 +0000
Subject: note 15530 deleted from function.mysql-pconnect by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-21784@lists.php.net to get a copy of this message
On the topic of benchmark, I ran the following code several times on one of our development servers. The development server is using php4isapi.dll (4.0.6) on the Windows 2000 SP2 platform. Though the ISAPI is unstable, permanent connections seem to be reused. The database is Mysql 3.23.39 on a Unix platform. Notice that I am closing the connection every pass. Doing a loop without calling mysql_close() will result in mysql_connect using the connection created the 1st pass. This "mistake" will result in mysql_connect being 50% faster than pconnect. I've also negated the time taken to close a connection since mysql_close() doesn't close permanent connections. <? $server=<ip to server>; $user=<dbuser>; $pass=<dbpass>; function getmicrotime(){ list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } echo "Executing 300 mysql_pconnect tests... "; $x=0; $timestart1=0; $timetotal1=0; for($x=0;$x<=300;$x++){ $timestart1=getmicrotime(); mysql_pconnect($server,$user,$pass); mysql_query("SELECT * FROM global_VisitorAnalysis"); $timetotal1+=getmicrotime()-$timestart1; mysql_close(); } echo "pconnect time: $timetotal1"; echo "Executing 300 mysql_connect tests... "; $x=0; $timestart2=0; $timetotal2=0; for($x=0;$x<=300;$x++){ $timestart2=getmicrotime(); mysql_connect($server,$user,$pass); mysql_query("SELECT * FROM global_VisitorAnalysis"); $timetotal2+=getmicrotime()-$timestart2; mysql_close(); } echo "connect time: $timetotal2"; echo "pconnect is ".(($timetotal1/$timetotal2)*100)."% more effective"; ?> My results: Executing 300 mysql_pconnect tests... pconnect time: 9.7010354995728 <BR>Executing 300 mysql_connect tests... connect time: 18.895518064499 <BR>pconnect is 51.34040499159% more effective<BR><BR>

« previous php.notes (#21784) next »