测试脚本:
file_get_contents(“http://phpor.net/xxx.php”);
strace过程:
[root@ja-4-65 ~]# strace -e network php b.php
socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = -1 EAFNOSUPPORT (Address family not supported by protocol) 虽然编译时声明支持IPv6,但是还是再检查是否支持IPv6, 见代码段1
socket(PF_FILE, SOCK_STREAM, 0) = 3
connect(3, {sa_family=AF_FILE, path=”/var/run/nscd/socket”}, 110) = -1 ENOENT (No such file or directory)
socket(PF_FILE, SOCK_STREAM, 0) = 3
connect(3, {sa_family=AF_FILE, path=”/var/run/nscd/socket”}, 110) = -1 ENOENT (No such file or directory)
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr(“172.16.108.100”)}, 28) = 0
send(3, “\342=\1\0\0\1\0\0\0\0\0\0\6ilogin\4sina\3com\2cn\0″…, 36, MSG_NOSIGNAL) = 36
recvfrom(3, “\342=\201\200\0\1\0\3\0\4\0\4\6ilogin\4sina\3com\2cn\0″…, 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr(“172.16.108.100”)}, [16]) = 220
socket(PF_NETLINK, SOCK_RAW, 0) = 3
bind(3, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=17124, groups=00000000}, [12]) = 0
sendto(3, “\24\0\0\0\26\0\1\3\246m\201P\0\0\0\0\0\0\0\0”, 20, 0, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 20
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{“<\0\0\0\24\0\2\0\246m\201P\344B\0\0\2\10\200\376\1\0\0\0\10\0\1\0\177\0\0\1″…, 4096}], msg_controllen=0, msg_flags=0}, 0) = 196
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{“\24\0\0\0\3\0\2\0\246m\201P\344B\0\0\0\0\0\0\1\0\0\0\10\0\1\0\177\0\0\1″…, 4096}], msg_controllen=0, msg_flags=0}, 0) = 20
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr(“10.77.7.251”)}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(37927), sin_addr=inet_addr(“10.49.4.65”)}, [16]) = 0
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr(“172.16.139.229”)}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(37927), sin_addr=inet_addr(“10.49.4.65”)}, [16]) = 0
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr(“10.49.4.245”)}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(37927), sin_addr=inet_addr(“10.49.4.65”)}, [16]) = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr(“10.49.4.245”)}, 16) = -1 EINPROGRESS (Operation now in progress)
getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
send(3, “GET /xxxx.php HTTP/1.0\r\n”, 30, MSG_DONTWAIT) = 30
send(3, “Host: phpor.net\r\n”, 26, MSG_DONTWAIT) = 26
send(3, “\r\n”, 2, MSG_DONTWAIT) = 2
recv(3, “HTTP/1.1 200 OK\r\nDate: Fri, 19 O”…, 8192, MSG_DONTWAIT) = 284
recv(3, “”, 8192, MSG_DONTWAIT) = 0
recv(3, “”, 8192, MSG_DONTWAIT) = 0
相关代码:
代码段1:php-5.3.3/main/network.c
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# if HAVE_IPV6 /* probe for a working IPv6 stack; even if detected as having v6 at compile * time, at runtime some stacks are slow to resolve or have other issues * if they are not correctly configured. * static variable use is safe here since simple store or fetch operations * are atomic and because the actual probe process is not in danger of * collisions or race conditions. */ if (ipv6_borked == -1) { int s; s = socket(PF_INET6, SOCK_DGRAM, 0); if (s == SOCK_ERR) { ipv6_borked = 1; } else { ipv6_borked = 0; closesocket(s); } } hints.ai_family = ipv6_borked ? AF_INET : AF_UNSPEC; # endif |