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

開發時PHP關閉暫存, OPCache.enable=0


OPCache 是 PHP 加速存取的功能,有用到的技術之一是暫存技術。


在開發時發現改完PHP源碼,但是網頁不能馬上看到修改結果,大約30秒到1分鐘才看得到修改後結果。原來是 bitnami WAMP 裡有開 opcache 功能。

開發PHP時關掉暫存快取功能,
file: php.ini
[opcache]
zend_extension=php_opcache.dll
; Determines if Zend OPCache is enabled
opcache.enable=0

References:
https://www.astralweb.com.tw/speed-up-your-magento-what-is-opcache/
https://www.ithome.com.tw/news/101602