Menu Close

PHP mysql_connect is slow for localhost

After some testing about the performance of my webpages, i understood that the problem of the slow loading was the function PHP mysql_connect that take about from 1 to 2 seconds to execute:

MysqlTime:1.7313570976257

After a little googling, i found that the problem is in the hostname parameter of the function:

// DB ACCESS
$hostname = "localhost";
$username = "user";
$password = "password";
$dbhandle = mysql_connect($hostname, $username, $password)
I found that php has issues with IPv6 and the solution is simple switching from “localhost” to “127.0.0.1”.
// DB ACCESS
$hostname = "127.0.0.1" ;
So now, the time to connect is:
MysqlTime:0.01671314239502;
Not so bad right?
Posted in News, Web Development

Leave a Reply

Your e-mail address will not be published. Required fields are marked *