1

我正在寻找最快的方法来检查链接是否在远程服务器上工作/存在,如果没有尝试另一个链接。类似于 nginx 中的“try_files”,仅用于链接...

例如:

try first 
header("Location:" . $VIDEO_1);
if there's no $VIDEO_1 try
header("Location:" . $VIDEO_2);
if there's no $VIDEO_2 try
header("Location:" . $VIDEO_3);

目前我正在使用一个检查大小并发送标题的函数......但是文件大小检查很慢

if($file_size > "9000000"){
        header("Content-type: video/x-flv");
        header("Location:" . $VIDEO . $dop);
}else{
        header("Content-type: video/x-flv");
        header("X-Accel-Redirect: /".$_GET["filename"].$dop);
}
4

1 回答 1

1

由于它在远程服务器上,您可以使用get_headers()

$header = get_headers("http://stackoverflow.com/users/flair/1401975.png");
preg_match('/\d{3}/', $header[0], $code); // Extracting the HTTP status code

if($code[0] < 400){ // Or maybe just $code[0] == 200 ? http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
    echo 'EXISTS !!!';
}else{
    echo 'Doesn\'t exists';
}
于 2013-03-17T23:10:17.417 回答