【发布时间】:2012-07-26 08:29:49
【问题描述】:
我正在尝试找到一个最佳解决方案来保存 性能、内存使用情况 等,以检查文件是否存在于不同的域中。在我的例子中,该文件是一个 XML,大小可以在 10KB 到 10MB 之间。
其中哪一个最适合使用?如果您有更好的方法,我很乐意改用它。
谢谢
卷曲
$ch = curl_init("http://www.example.com/hello.xml");
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// $retcode > 400 -> not found, $retcode = 200, found.
curl_close($ch);
FOPEN
$url = "http://www.example.com/hello.xml";
if (@fopen($url, "r")) {
echo "File Exists";
} else {
echo "Can't Connect to File";
}
【问题讨论】:
-
卷曲速度更快。见this previous question on SO
-
如果是 XML 文件,为什么不
simplexml_load_file?