不确定是不是因为它已经过时了,但是它一直在运行一个网站并且直到最近(1周)才工作 - 服务器还没有更新,所以我不确定破坏脚本会发生什么。< / p>
这是我在debian服务器上运行(并且失败)的测试脚本:
<?php
$url = "http://www.andyloughran.co.uk/test.html";
echo $url."\n";
$test = file_get_contents($url);
echo $test;
通常应该返回'ndy test'或类似的东西。
然而,在debian盒子上它只是超时。
我已经检查过了,我可以找到该文件:
<?php
exec('wget http://www.andyloughran.co.uk/test.html');
所以我不确定file_get_contents中的内容是什么。
我已经检查过,allow_fopen_url设置为On。
我可以提供建议,不仅仅是修复这个问题,而是研究如何调试php以便能够在将来自己识别问题。
目前卷毛不是一个真正的选择,因为我更感兴趣的是找出它停止工作的原因,而不是替代方案。
谢谢!
这是strace错误:
open("/dev/urandom", O_RDONLY) = 3
read(3, "\202\231\320\206"..., 4) = 4
close(3) = 0
open("/dev/urandom", O_RDONLY) = 3
read(3, "cdO\37"..., 4) = 4
close(3) = 0
brk(0x9133000) = 0x9133000
open("http_test.php", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=187, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7837000
read(3, "<?php\n\nini_set('display_errors', "..., 4096) = 187
_llseek(3, 0, [0], SEEK_SET) = 0
time(NULL) = 1348748612
fstat64(0, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0), ...}) = 0
fstat64(0, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7836000
_llseek(0, 0, 0xbfae579c, SEEK_CUR) = -1 ESPIPE (Illegal seek)
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0), ...}) = 0
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7835000
_llseek(1, 0, 0xbfae579c, SEEK_CUR) = -1 ESPIPE (Illegal seek)
fstat64(2, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 0), ...}) = 0
_llseek(2, 0, 0xbfae579c, SEEK_CUR) = -1 ESPIPE (Illegal seek)
getcwd("/root"..., 4096) = 6
time(NULL) = 1348748612
lstat64("/root", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/root/http_test.php", {st_mode=S_IFREG|0644, st_size=187, ...}) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfae3798) = -1 ENOTTY (Inappropriate ioctl for device)
read(3, "<?php\n\nini_set('display_errors', "..., 8192) = 187
read(3, ""..., 4096) = 0
read(3, ""..., 8192) = 0
close(3) = 0
munmap(0xb7837000, 4096) = 0
write(1, "http://www.andyloughran.co.uk/tes"..., 40http://www.andyloughran.co.uk/test.html
) = 40
socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = 3
close(3) = 0
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=28901, groups=00000000}, [12]) = 0
time(NULL) = 1348748612
sendto(3, "\24\0\0\0\26\0\1\3DEdP\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\0\24\0\2\0DEdP\345p\0\0\2\10\200\376\1\0\0\0\10\0\1\0\177\0\0\1\10"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 156
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"@\0\0\0\24\0\2\0DEdP\345p\0\0\n\200\200\376\1\0\0\0\24\0\1\0\0\0\0\0\0"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 64
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\24\0\0\0\3\0\2\0DEdP\345p\0\0\0\0\0\0\1\0\0\0\24\0\1\0\0\0\0\0\0"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 20
close(3) = 0
stat64("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=95, ...}) = 0
open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=141, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7837000
read(3, "127.0.0.1 localhost.localdomain l"..., 4096) = 141
read(3, ""..., 4096) = 0
close(3) = 0
munmap(0xb7837000, 4096) = 0
open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=141, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7837000
read(3, "127.0.0.1 localhost.localdomain l"..., 4096) = 141
read(3, ""..., 4096) = 0
close(3) = 0
munmap(0xb7837000, 4096) = 0
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=32850, ...}) = 0
mmap2(NULL, 32850, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7820000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/libnss_dns.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\220\v\0\0004\0\0\0x"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0644, st_size=17880, ...}) = 0
mmap2(NULL, 20616, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xca5000
mmap2(0xca9000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3) = 0xca9000
close(3) = 0
munmap(0xb7820000, 32850) = 0
stat64("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=95, ...}) = 0
gettimeofday({1348748612, 441933}, NULL) = 0
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, 28) = 0
fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
gettimeofday({1348748612, 442194}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
send(3, "2k\1\0\0\1\0\0\0\0\0\0\3www\fandyloughran\2co\2"..., 40, MSG_NOSIGNAL) = 40
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLIN}])
ioctl(3, FIONREAD, [102]) = 0
recvfrom(3, "2k\201\200\0\1\0\0\0\1\0\0\3www\fandyloughran\2co\2"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, [16]) = 102
close(3) = 0
gettimeofday({1348748612, 755352}, NULL) = 0
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, 28) = 0
fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
gettimeofday({1348748612, 755589}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
send(3, "\312-\1\0\0\1\0\0\0\0\0\0\3www\fandyloughran\2co\2"..., 56, MSG_NOSIGNAL) = 56
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLIN}])
ioctl(3, FIONREAD, [121]) = 0
recvfrom(3, "\312-\201\203\0\1\0\0\0\1\0\0\3www\fandyloughran\2co\2"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, [16]) = 121
close(3) = 0
stat64("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=95, ...}) = 0
gettimeofday({1348748613, 222946}, NULL) = 0
socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, 28) = 0
fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
gettimeofday({1348748613, 223253}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
send(3, "\254Q\1\0\0\1\0\0\0\0\0\0\3www\fandyloughran\2co\2"..., 40, MSG_NOSIGNAL) = 40
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLIN}])
ioctl(3, FIONREAD, [56]) = 0
recvfrom(3, "\254Q\201\200\0\1\0\1\0\0\0\0\3www\fandyloughran\2co\2"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, [16]) = 56
close(3) = 0
gettimeofday({1348748613, 400717}, NULL) = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("85.119.82.243")}, 16) = -1 EINPROGRESS (Operation now in progress)
poll([{fd=3, events=POLLIN|POLLOUT|POLLERR|POLLHUP}], 1, 60000) = 1 ([{fd=3, revents=POLLOUT}])
getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
fcntl64(3, F_SETFL, O_RDWR) = 0
send(3, "GET /test.html HTTP/1.0\r\n"..., 25, MSG_DONTWAIT) = 25
send(3, "Host: www.andyloughran.co.uk\r\n"..., 30, MSG_DONTWAIT) = 30
send(3, "User-Agent: PHP\r\n"..., 17, MSG_DONTWAIT) = 17
send(3, "\r\n"..., 2, MSG_DONTWAIT) = 2
poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 60000^C <unfinished ...>
答案 0 :(得分:1)
答案 1 :(得分:0)
前一段时间我遇到了同样的问题。这是一个DNS问题。重启Web服务器有所帮助。
答案 2 :(得分:0)
file_get_contents无法使用URI。 试试这个:
$Stuff = file_get_contents($_SERVER['DOCUMENT_ROOT']."path/filename");
file_get_contents很乐意&#34;看&#34;一条本地和可访问的路径。它会将文件内容呈现为一种&#34;功能 - 谢谢你&#34; ;)