2018年11月27日 星期二

PHP develop on Win10, Domain Name Resolve Problem

When I use Bitnami WAMP on the Win10, I found out  that one connection consumes about 1.0x second. So below code needs about 4 seconds. Even when I use command line interface(CLI) to execute  it, such as php.exe or mysql.exe.

This is domain name resolve problem.

To Solve this problem you can replace "localhost" to "127.0.0.1".


$dbh = new PDO('mysql:host=localhost;dbname=dbname', 'user', 'pass');
$dbh = null;
$dbh = new PDO('mysql:host=localhost;dbname=dbname', 'user', 'pass');
$dbh = null;
$dbh = new PDO('mysql:host=localhost;dbname=dbname', 'user', 'pass');
$dbh = null;
$dbh = @new mysqli('localhost','dbname','pass','dbname');
$dbh->close();


Refer:
https://stackoverflow.com/questions/9800577/why-is-constructing-pdo-connection-slow

沒有留言: