当我在 CLI 模式下运行 PHP 时(CentOS 6.5 下的 PHP 5.6.6 使用 VirtualBox 作为虚拟机运行),即使我只检查版本并且禁用 php.ini 文件,也会有几秒钟的延迟:
time php -n -v
PHP 5.6.6 (cli) (built: Apr 2 2015 14:18:24)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
real 0m5.066s
user 0m0.012s
sys 0m0.006s
该问题与 PHP 正在执行的 DNS 调用有关。看here https://serverfault.com/questions/586141/php-cli-with-imap-5-second-startup-delay and here https://bugs.php.net/bug.php?id=65632.
解决办法是添加主机名
[root@dev-machine ~]# hostname
dev-machine.com
到/etc/hosts:
127.0.0.1 dev-machine.com
Result:
time php -n -v
PHP 5.6.6 (cli) (built: Apr 2 2015 14:18:24)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
real 0m0.018s
user 0m0.012s
sys 0m0.004s
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)