All PHP CLI scripts are waiting for host resolution on Mac OS X

I get freezes when executing PHP commands on my Ubuntu homestead vagrant box. There is a significant lag before the console even starts php cli execution.

Ran strace -vyT -S time php artisan help from a stray box. Everything gets stuck for several minutes the first time I access recvfrom(3 , but I have no idea why:

 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 :

 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 

Contents of /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 now affects EVERY unrelated stray box that I have, and not just the Homestead box. Almost every PHP command in each field is delayed for 5-15 minutes for each CLI run. If you need to invoke a chain of commands, it may take an hour to complete the process, which should take 30 seconds.

It started after the Mac running these windows was upgraded to El Capitan.

Depending on the roaming box, sometimes this line is strace:

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

Replaced by:

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

IP 192.168.56.1 seems to be the default router for VirtualBox.

Please note that all roaming boxes are either standard configurations or those that work without problems in my other Mac / Windows user group.

Vagrant 1.7.4 and VirtualBox 4.3.30.

In response to a route -n request:

 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 :

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

Why hhvm appears, I do not know, because the box must use the standard PHP interpreter.

+6
source share
3 answers

tl; dr : I blame the xdebug client. Try disabling xdebug on Ubuntu.

My rationale :

I do not see any host resolution issues in the strace log.

First it checks /etc/resolv.conf , 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>

Port 9000 is the default for xdebug unless overridden in /etc/php5/mods-available/xdebug.ini or similar.

write(3<socket:[78362]>, "478\0<?xml version=\"1.0\" encoding"..., 483) = 483 <0.000042> looks like a message sent from the xdebug extension to the client.

It waits 2 minutes recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS then recvfrom(3, 0x7ffc489b16d0, 128, 0, 0, 0) = ? ERESTARTSYS and executes your PHP script.

The latency has been reduced to 200 ms since v2.2.4: https://github.com/xdebug/xdebug/pull/90

Assuming disabling xdebug fixes the problem, there are several options:

  • upgrade xdebug
  • configure xdebug to run on demand only with xdebug.remote_autostart=off
  • save / disable xdebug
  • always hold the xdebug client and make sure the ports are mapped correctly and not hung
0
source

The problem is with the host solution. if you are trying to use your ip instead of localhost ip 127.0.0.1 . better to use in /etc/hosts , for example:

 yourip hostname.example.com hostname 

eg

 10.0.2.20 test.example.com test 

and remove the localhost associated with /etc/hosts , or continue. the system will try to make the first entry, and if you are not using ipv6 , you can also delete the entry associated with ipv6.

EDIT: your /etc/resolv.conf file should have a line below

 nameserver 127.0.0.1 

also adds a stray network by default, because your output shows that it is trying to connect to this, but if you do not want to use, you can skip. you are using 127.0.0.1 , so at least it should be there. You can take help to go from here to here .

0
source

Well, this seems like a DNS issue. I assume that your computer will not be able to resolve DNS through the given host name, or the DNS server is just slow. My advice is to install a local caching DNS server and use it and add something to the / etc / hosts file on the private network that will not be served by DNS. Use NetworkManager or any other network service that you should add 127.0.0.1 as a viable (and preferred) DNS server and everything should work smoothly. If you are using ubuntu, this should be as simple as sudo apt-get install bind9.

If you want to diagnose the problem, first install dnsutils to get dig and nslookup, and try asking for something, for example www.google.co.uk, see how long it takes and which server is authoritative. Then try using dig to be more specific, poll the server directly, query SOA directly, see if you can find out where the weakest link is.

Probably a router that advertises itself as a DNS service through DHCP, but does not work correctly when clicked.

0
source

All Articles