PDO is slower on PHP 5.4 and Apache 2.4.3

Possible duplicate:
mysql_connect (localhost / 127.0.0.1) on a Windows platform

I just updated my versions of Apache and PHP on a development machine, and PDO completely disappeared.

This is a dead simple PDO class:

class PDO_DBH { public static function openSesame() { echo '<p>start openSesame: </p>'.microtime(true); $db_username = 'root'; $db_password = 'pass'; try { $dbh = new PDO('mysql:host=localhost;dbname=DB_NAME', $db_username, $db_password); $dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); echo '<p>end successful openSesame: </p>'.microtime(true); return $dbh; } catch (PDOException $e) { echo '<p>end failed openSesame: </p>'.microtime(true); return 'PDO database access error!'; } } } 

Before upgrading and currently on other dev machines, a typical page will load in a second, not more than two.

Now, through the wonders of microtime(true) , I see that it takes a full second to open a connection.

A typical page can create a new $dbh and then $dbh = null; its 20 times, since different objects and methods will look for the necessary data. This has never been a problem on other machines or on my web host.

Where am I wrong here?

+4
source share
1 answer

This was just an assumption - but on Windows machines changing to 127.0.0.1 instead of localhost , the trick.

+4
source

Source: https://habr.com/ru/post/1442899/


All Articles