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 に答える