PHP CLI has a few seconds delay

梦想与她 提交于 2020-01-04 21:16:22

问题


When I run PHP in the CLI mode (PHP 5.6.6 under CentOS 6.5 running as VM using VirtualBox) it has a few seconds of delay even if I only check version and there is php.ini file disabled:

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:


The problem is related to DNS call PHP is doing. See here and here.

The solution is to add hostname

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

to /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


来源:https://stackoverflow.com/questions/29510665/php-cli-has-a-few-seconds-delay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!