简体   繁体   English

所有流浪的PHP CLI脚本都在Mac OS X上等待主机解析

[英]All vagrant PHP CLI scripts hang waiting on host resolution on Mac OS X

I've been getting hangs when executing PHP commands on my Homestead vagrant box running Ubuntu. 在运行Ubuntu的Homestead vagrant盒子上执行PHP命令时,我一直在挂起。 There is a significant lag before the console even starts the php cli execution. 在控制台甚至启动php cli执行之前有一个显着的延迟。

Ran strace -vyT -S time php artisan help from vagrant box. Ran strace -vyT -S time php artisan help从流浪者的盒子。 Everything gets stuck for several minutes on the first to last call to recvfrom(3 , but I have no idea why: 在第一次到最后一次调用recvfrom(3 ,所有东西都会卡住几分钟recvfrom(3 ,但我不明白为什么:

open("/etc/resolv.conf", O_RDONLY|O_CLOEXEC) = 3 <0.000010>
fstat(3</run/resolvconf/resolv.conf>, {st_dev=makedev(0, 16), st_ino=7632, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=171, st_atime=2015/10/17-04:53:56, st_mtime=2015/10/17-04:53:54, st_ctime=2015/10/17-04:53:54}) = 0 <0.000007>
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fed9385c000 <0.000008>
read(3</run/resolvconf/resolv.conf>, "# Dynamic resolv.conf(5) file fo"..., 4096) = 171 <0.000010>
read(3</run/resolvconf/resolv.conf>, "", 4096) = 0 <0.000006>
close(3</run/resolvconf/resolv.conf>)   = 0 <0.000008>
munmap(0x7fed9385c000, 4096)            = 0 <0.000011>
uname({sysname="Linux", nodename="homestead", release="3.13.0-65-generic", version="#106-Ubuntu SMP Fri Oct 2 22:08:27 UTC 2015", machine="x86_64", domainname="(none)"}) = 0 <0.000006>
stat("/etc/resolv.conf", {st_dev=makedev(0, 16), st_ino=7632, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=171, st_atime=2015/10/17-04:53:56, st_mtime=2015/10/17-04:53:54, st_ctime=2015/10/17-04:53:54}) = 0 <0.000008>
open("/etc/hosts", O_RDONLY|O_CLOEXEC)  = 3 <0.000009>
fstat(3</etc/hosts>, {st_dev=makedev(8, 1), st_ino=1161, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=251, st_atime=2015/10/16-18:57:29, st_mtime=2014/10/03-01:16:42, st_ctime=2014/10/03-01:16:42}) = 0 <0.000005>
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fed9385c000 <0.000008>
read(3</etc/hosts>, "127.0.0.1 localhost\n\n# The follo"..., 4096) = 251 <0.000009>
read(3</etc/hosts>, "", 4096)           = 0 <0.000007>
close(3</etc/hosts>)                    = 0 <0.000007>
munmap(0x7fed9385c000, 4096)            = 0 <0.000010>
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3 <0.000012>
fcntl(3<socket:[78362]>, F_SETFL, O_RDONLY|O_NONBLOCK) = 0 <0.000006>
connect(3, {sa_family=AF_INET, sin_port=htons(9000), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress) <0.000094>
select(4, [3<socket:[78362]>], [3<socket:[78362]>], [3<socket:[78362]>], {0, 200000}) = 1 (out [3], left {0, 199997}) <0.000010>
getpeername(3, {sa_family=AF_INET, sin_port=htons(9000), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0 <0.000007>
fcntl(3<socket:[78362]>, F_SETFL, O_RDONLY) = 0 <0.000006>
setsockopt(3, SOL_TCP, TCP_NODELAY, "\1\0\0\0\0\0\0\0", 8) = 0 <0.000008>
write(3<socket:[78362]>, "478\0<?xml version=\"1.0\" encoding"..., 483) = 483 <0.000042>
brk(0x2f93000)                          = 0x2f93000 <0.000472>
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <4.940291>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.072574>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.033758>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.038904>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.026003>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.024057>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.055221>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.058240>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.027569>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.056877>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.025934>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.076699>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.089092>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.254680>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.131634>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.065721>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.042778>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.072277>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.044424>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) <0.080704>
--- SIGWINCH {si_signo=SIGWINCH, si_code=SI_KERNEL} ---
recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = -1 ECONNRESET (Connection reset by peer) <113.777721>

Here is the contents of /etc/hosts : 这是/etc/hosts的内容:

127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
127.0.1.1 homestead homestead

The contents of /etc/resolve.conf : /etc/resolve.conf的内容:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.0.2.3

The problem is now affecting EVERY unrelated vagrant box I have, not just the Homestead box. 问题是现在影响我所拥有的每个无关的流浪者盒子,而不仅仅是Homestead盒子。 Almost every PHP command on each box is stalled by 5-15 minutes for each CLI execution. 对于每个CLI执行,几乎每个盒子上的每个PHP命令都会停止5-15分钟。 If a chain of commands must be called, it can take an hour to finish a process that should take 30 seconds. 如果必须调用一系列命令,则可能需要一个小时才能完成一个需要30秒的过程。

This started after the Mac these boxes are run on was upgraded to El Capitan. 在Mac运行之后,这些盒子运行升级为El Capitan。

Depending on the vagrant box, sometimes this strace line: 根据流浪者的盒子,有时这个strace线:

connect(3, {sa_family=AF_INET, sin_port=htons(9000), sin_addr=inet_addr("127.0.0.1")}, 16) = 0

Is replaced by: 替换为:

connect(3, {sa_family=AF_INET, sin_port=htons(9000), sin_addr=inet_addr("192.168.56.1")}, 16) = 0

The IP 192.168.56.1 appears to be the default router for VirtualBox. IP 192.168.56.1似乎是VirtualBox的默认路由器。

Please note, all vagrant boxes are either standard config or those that work without issue on my other team member's Mac/Windows systems. 请注意,所有流浪盒都是标准配置或在我的其他团队成员的Mac / Windows系统上没有问题的那些。

Vagrant 1.7.4 and VirtualBox 4.3.30. Vagrant 1.7.4和VirtualBox 4.3.30。

In response to request route -n : 响应请求route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.2.2        0.0.0.0         UG    0      0        0 eth0
10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.10.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1

Results for sudo netstat -tulnp | grep 9000 结果为sudo netstat -tulnp | grep 9000 sudo netstat -tulnp | grep 9000 : sudo netstat -tulnp | grep 9000

tcp6       0      0 :::9000                 :::*                    LISTEN      1317/hhvm

Why hhvm is showing up, I don't know, because the box is supposed to be using the standard PHP interpreter. 为什么hhvm出现,我不知道,因为该框应该使用标准的PHP解释器。

Problem seems related to hostname resolve. 问题似乎与主机名解析有关。 if you are trying use your ip instead of localhost ip 127.0.0.1 . 如果你正在尝试使用你的IP而不是localhost ip 127.0.0.1 better to use in /etc/hosts like : 最好在/etc/hosts使用,例如:

yourip  hostname.example.com hostname

for example 例如

10.0.2.20 test.example.com test

and remove localhost related from /etc/hosts or keep at last. 并删除/etc/hosts相关的localhost或最后保留。 system will try to take first entry and if you are not using ipv6 then you can remove ipv6 related entry also. 系统将尝试进入第一个条目,如果您不使用ipv6那么您也可以删除ipv6相关条目。

EDIT: your /etc/resolv.conf file should have bellow line 编辑:你的/etc/resolv.conf文件应该有下面的行

nameserver 127.0.0.1

also add vagrant default network because your output shows it trying to connect that but if you don't want to use then you can skip. 还添加了vagrant默认网络,因为你的输出显示它试图连接但是如果你不想使用那么你可以跳过。 you are using 127.0.0.1 so at least it should be there.you can take help for changing from here and here . 你使用的是127.0.0.1所以至少它应该在那里。你可以从这里这里获得帮助。

tl;dr : I blame xdebug client. tl;博士 :我责备xdebug客户端。 Try to disable xdebug on Ubuntu. 尝试在Ubuntu上禁用xdebug。

My rationale : 我的理由

I don't see any problems with host resolution in the strace log there. 我没有在strace日志中看到主机解析有任何问题。

It checks /etc/resolv.conf first, then /etc/hosts and connects to 127.0.0.1:9000 connect(3, {sa_family=AF_INET, sin_port=htons(9000), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress) <0.000094> 它首先检查/etc/resolv.conf ,然后检查/etc/hosts并连接到127.0.0.1:9000 connect(3, {sa_family=AF_INET, sin_port=htons(9000), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress) <0.000094>

Port 9000 is the default for xdebug, unless redefined in /etc/php5/mods-available/xdebug.ini or similar. 端口9000是xdebug的默认设置,除非在/etc/php5/mods-available/xdebug.ini重新定义或类似。

write(3<socket:[78362]>, "478\\0<?xml version=\\"1.0\\" encoding"..., 483) = 483 <0.000042> looks like a message sent from xdebug extension to the client. write(3<socket:[78362]>, "478\\0<?xml version=\\"1.0\\" encoding"..., 483) = 483 <0.000042>看起来像是从xdebug扩展发送到客户端的消息。

It waits for 2 minutes recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS 等待2分钟recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS , then gives up and execute your php script. 然后recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS放弃并执行你的php脚本。

The wait time has been reduced to 200 ms since v2.2.4: https://github.com/xdebug/xdebug/pull/90 自v2.2.4起,等待时间减少到200毫秒: https//github.com/xdebug/xdebug/pull/90

Assuming that disabling of xdebug resolve the problem, there are few options: 假设禁用xdebug解决了问题,几乎没有选项:

  • upgrade xdebug 升级xdebug
  • configure xdebug to start on-demand only with xdebug.remote_autostart=off 将xdebug配置为仅使用xdebug.remote_autostart=off按需启动
  • keep enabling/disabling xdebug 继续启用/禁用xdebug
  • keep xdebug client always on and ensure ports are mapped correctly and it does not hung 始终保持xdebug客户端正常运行,并确保端口正确映射,并且不会挂起

Well it feels like a DNS problem. 那感觉就像是一个DNS问题。 My guess would be either your machine can't resolve DNS via the given host name, or the DNS server is just slow. 我的猜测是你的机器无法通过给定的主机名解析DNS,或者DNS服务器只是很慢。 My advice would be to install a caching DNS server locally, and use that, and add to the /etc/hosts file anything in a private network, that won't be served from DNS. 我的建议是在本地安装缓存DNS服务器,然后使用它,并将/ etc / hosts文件添加到专用网络中的任何内容,这些文件将不会从DNS提供。 Use NetworkManager or whichever network service you have to add 127.0.0.1 as a viable (and preferred) DNS server, and things should work smoothly. 使用NetworkManager或您必须添加127.0.0.1作为可行(和首选)DNS服务器的网络服务,事情应该顺利进行。 If you're using ubuntu, that should be as easy as sudo apt-get install bind9. 如果您使用的是ubuntu,那应该像sudo apt-get install bind9一样简单。

If you want to diagnose the problem, first install dnsutils, to get dig and nslookup, and try querying something, like www.google.co.uk, see how long it takes and which server is authoritative. 如果你想诊断问题,首先安装dnsutils,以获取dig和nslookup,并尝试查询某些内容,例如www.google.co.uk,查看需要多长时间以及哪个服务器具有权威性。 Then try using dig, to be more specific, interrogate the server directly, interrogate the SOA directly, see if you can figure out where the weakest link is. 然后尝试使用dig,更具体地说,直接询问服务器,直接询问SOA,看看你是否可以找出最薄弱环节的位置。

It's probably a router that's advertising itself as DNS service via DHCP, but isn't working right when pressed. 它可能是一个通过DHCP将自己宣传为DNS服务的路由器,但在按下时无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM