php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63525 php5.4.8 connecting to mysql is slower then php5.2.6
Submitted: 2012-11-15 09:09 UTC Modified: 2012-11-16 07:36 UTC
From: admin at wudimei dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.4.8 OS: windows 7
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: admin at wudimei dot com
New email:
PHP Version: OS:

 

 [2012-11-15 09:09 UTC] admin at wudimei dot com
Description:
------------
php5.4.8 connecting to mysql is slower then php5.2.8

i use php5.4.8 to connect the mysql,it's slow!it take about 1.0138568878174 seconds.
then i switch to php5.2.6 ,it only take 0.00234985351562 seconds.

please improve it
thank you!

yang qingrong

Test script:
---------------
<?php
$a = microtime( true );
$conn = mysql_connect("localhost","root","123456");
mysql_select_db("yqr");
$q = mysql_query("show tables");
while( $r = mysql_fetch_assoc( $q ))
{
    print_r( $r );
}
 echo microtime(true ) - $a; echo " seconds"; exit();
?>

php5.4.8 output:

Array ( [Tables_in_yqr] => account_book ) Array ( [Tables_in_yqr] => customer ) Array ( [Tables_in_yqr] => domain ) Array ( [Tables_in_yqr] => friends ) Array ( [Tables_in_yqr] => hourly_work ) Array ( [Tables_in_yqr] => hourly_work_project ) Array ( [Tables_in_yqr] => notepad ) Array ( [Tables_in_yqr] => notepad_ctg ) Array ( [Tables_in_yqr] => schedule ) 1.0138568878174 seconds

php 5.2.6 output
Array ( [Tables_in_yqr] => account_book ) Array ( [Tables_in_yqr] => customer ) Array ( [Tables_in_yqr] => domain ) Array ( [Tables_in_yqr] => friends ) Array ( [Tables_in_yqr] => hourly_work ) Array ( [Tables_in_yqr] => hourly_work_project ) Array ( [Tables_in_yqr] => notepad ) Array ( [Tables_in_yqr] => notepad_ctg ) Array ( [Tables_in_yqr] => schedule ) 0.00234985351562 seconds


Patches

issue-above (last revision 2012-11-15 09:10 UTC by admin at wudimei dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-15 09:37 UTC] andrey@php.net
-Status: Open +Status: Feedback
 [2012-11-15 09:37 UTC] andrey@php.net
Can you try 127.0.0.1 instead of localhost and report the connect time?
 [2012-11-15 11:59 UTC] admin at wudimei dot com
i use ip,not localhost.
http://127.0.0.18/wudimei_show/admin_S2D3L56N8K5L/component_types.php?act=index
 [2012-11-15 11:59 UTC] admin at wudimei dot com
-Status: Feedback +Status: Open
 [2012-11-15 12:11 UTC] yangqingrong at wudimei dot com
i edited the code like this:

<?php
$a = microtime( true );
$conn = mysql_connect("localhost","root","123456");
mysql_select_db("yqr");
$q = mysql_query("show tables");
while( $r = mysql_fetch_assoc( $q ))
{
    print_r( $r );
}
 echo "<br /><b>connect to mysql take ". (microtime(true ) - $a); echo " seconds</b>"; 
 phpinfo();
 
?>


to see the result,copy the url below and paste it to the address bar of browser:

http://www.wudimei.com/data/YangQingrong/php5.2.6.jpg
http://www.wudimei.com/data/YangQingrong/php5.4.8.jpg
 [2012-11-15 15:43 UTC] rasmus@php.net
You said you used 127.0.0.1 but your code clearly shows "localhost". Windows is 
probably trying to use ipv6 for "localhost" first and MySQL isn't listening on 
::1 so it has to time out there first before trying 127.0.0.1. You can either fix 
your Hosts file and remove ::1 (probably a bad idea) or simply use 127.0.0.1 in 
your code.
 [2012-11-15 15:43 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2012-11-16 07:36 UTC] admin at wudimei dot com
<?php
$a = microtime( true );
$conn = mysql_connect("127.0.0.1","root","123456");
mysql_select_db("yqr");
$q = mysql_query("show tables");
while( $r = mysql_fetch_assoc( $q ))
{
    print_r( $r );
}
 echo "<br /><b>connect to mysql take ". (microtime(true ) - $a); echo " seconds</b>"; 
 phpinfo();
 
?>


connect to mysql take 0.0034029483795166 seconds

thanks rasmus@php.net very much,this issue solved!
thank you again!
best regards
yangqingrong
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 09:01:29 2024 UTC