我需要查看我的cdn上是否存在特定图像.
我尝试过以下内容并不起作用:
if (file_exists(http://www.example.com/images/$filename)) {
    echo "The file exists";
} else {
    echo "The file does not exist";
}
即使图像存在或不存在,它总是说"文件存在".我不确定为什么它不起作用......
我需要一个include只包含文件的函数/语句.PHP中有一个吗?
您可能建议使用@include但该方法存在问题 - 如果要包含的文件存在,如果解析器在包含的文件中发现错误,PHP将不会输出警告.
我做了一些测试来比较和测量两种功能的速度.is_file似乎比file_exists快几倍(我使用10000次迭代).我想知道PHP或OS是否为这些功能使用了一些缓存,或者是否始终访问HDD?我想不,但我想知道......
我用过这段代码:
<?php
$time = microtime();
$time = explode(' ', $time);
$begintime = $time[1] + $time[0];
for($i=0;$i<10000;$i++)
    file_exists('/Applications/MAMP/htdocs/index.php');
$time = microtime();
$time = explode(" ", $time);
$endtime = $time[1] + $time[0];
$totaltime = ($endtime - $begintime);
echo 'PHP parsed this in ' .$totaltime. ' seconds.</br>';
$time = microtime();
$time = explode(" ", $time);
$begintime = $time[1] + $time[0];
for($i=0;$i<10000;$i++)
    is_file('/Applications/MAMP/htdocs/index.php');
$time = microtime();
$time = explode(" ", $time);
$endtime = $time[1] + $time[0];
$totaltime = ($endtime …