2012-09-27 75 views
0

不知道是否是因爲它是從生活中,但它已經運行一個網站和工作,直到最近(1周) - 服務器尚未更新,所以我不知道發生了什麼事打破劇本。的file_get_contents失敗的Debian(lenny中)服務器上

下面是我一直在Debian的服務器上運行(和失敗)測試腳本:

<?php 
$url = "http://www.andyloughran.co.uk/test.html"; 
echo $url."\n"; 
$test = file_get_contents($url); 
echo $test; 

通常應該返回「NDY測試」或類似的東西。

然而,在Debian框,它只是超時。

我檢查,我可以wget的文件:

<?php 
exec('wget http://www.andyloughran.co.uk/test.html'); 

所以我不知道它是什麼在不工作的file_get_contents。

我檢查和allow_fopen_url被設置爲開。

我不能只是解決這個問題,但工作如何調試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 ...> 
+3

什麼是錯誤信息? –

+1

也許不是一個PHP問題,但更像是一個DNS問題。 –

回答

1
  • 了allow_url_fopen =在php.ini中
  • 檢查你的DNS,平www.andyloughran.co.uk
  • 扔服務器從最近的窗口。
+0

我真的想用throw server選項。 DNS和allow_url_fopen已打開。 – andylockran

0

我有同樣的problemn前一陣子。這是一個DNS問題。重新啓動Webserver幫助。

+0

多數民衆贊成沒有幫助:( – andylockran

+0

strace表明,DNS查找是成功的,因爲是http GET /test.html請求 - 它只是立即發送回該服務器.. – andylockran

0

file_get_contents不適用於URI。 就試試這個:

$Stuff = file_get_contents($_SERVER['DOCUMENT_ROOT']."path/filename"); 

的file_get_contents會很高興「看到」本地和訪問路徑。它會將您的文件內容呈現爲一種「功能 - 感謝您」;)