PHP CLI有几秒钟的延迟

时间:2015-04-08 09:20:03

标签: php centos command-line-interface delay

当我在CLI模式下运行PHP(使用VirtualBox作为VM运行的CentOS 6.5下的PHP 5.6.6)时,即使我只检查版本并且禁用了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

1 个答案:

答案 0 :(得分:4)

问题与PHP正在进行的DNS调用有关。请参阅herehere

解决方案是添加主机名

[root@dev-machine ~]# hostname
dev-machine.com

到/ etc / hosts:

127.0.0.1 dev-machine.com

结果:

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