直到今天,我使用PHP的readfile()
函数通过CloudFront在S3上输出图像。
现在,我在这个功能上超时了。在浏览器中粘贴相同的URL时,它只是工作,并显示图像。
要明确:它一直工作到今天,我不记得改变PHP的配置。
phpinfo()
说:
所以我的问题是:如何调试此问题?
答案 0 :(得分:0)
让我们检查几个较小的位,看看我们是否可以隔离它:
确保allow_url_fopen
is enabled。
确保可以解析DNS请求。
确保IPv4连接正常工作。*
确保IPv6连接正常工作。*
使用file_get_contents()
尝试整个事物,它使用相同的fopen包装器。
*请注意,检查这两个非常重要。我过去曾经历过PHP使用的不同系统级工具使用不同版本的IP的经验。它与curl_*
相当混乱,但file_get_contents()
没有。
这是一个检查每个内容的脚本:
<?php
//Not relevant - Formatting for web browsers...
if (php_sapi_name() !== "cli") {
echo "<pre>";
}
//Ensure PHP is configured correctly.
$allowUrlFopen = ini_get('allow_url_fopen');
if($allowUrlFopen){
echo "Success: allow_url_fopen is enabled.\n";
} else {
echo "FAILURE: allow_url_fopen is disabled.\n";
}
//Check that DNS is working.
$dns = dns_get_record("www.google.com");
if($dns){
echo "Success: DNS has resolved.\n";
} else {
echo "FAILURE: DNS did not resolve.\n";
}
//A Google webserver (IPv4). the IP provided was listed in $dns.;
$ipv4 = curl_init("http://216.58.217.36");
curl_setopt($ipv4, CURLOPT_RETURNTRANSFER, true);
curl_exec($ipv4);
$statusCode = curl_getinfo($ipv4, CURLINFO_HTTP_CODE);
//The server responded at all, what it responded with isn't important.
if($statusCode >= 100){
echo "Success: Accessing Google's IPv4 web server succeeded.\n";
} else {
echo "FAILURE: Accessing Google's IPv4 web server failed.\n";
}
//A Google webserver (IPv6). The IP provided was listed in $dns.;
$ipv6 = curl_init("http://2607:f8b0:400f:803::2004");
curl_setopt($ipv6, CURLOPT_RETURNTRANSFER, true);
curl_exec($ipv6);
$statusCode = curl_getinfo($ipv6, CURLINFO_HTTP_CODE);
if($statusCode >= 100){
echo "Success: Accessing Google's IPv6 web server succeeded.\n";
} else {
echo "FAILURE: Accessing Google's IPv6 web server failed.\n";
}
//Fetch remote data via fopen url wrappers (file_get_contents utilizies them).
$file = file_get_contents("http://www.google.com");
$characters = strlen($file);
if($characters){
echo "Success: using fopen wrappers to fetch remote data via a URL succeeded.\n";
} else {
echo "FAILURE: using fopen wrappers to fetch remote data via a URL failure.\n";
}
if (php_sapi_name() !== "cli") {
echo "</pre>";
}
请务必使用较低级别的系统工具调查任何故障。我在操作系统上的所有 IPv6超时时遇到了与此类似的问题。禁用IPv6系统修复了它。