There are 5 streams on a website. I need to detect if these streams exist. If not, there are some audio files to play instead.
I'm using html5 to play the stream and stream urls look like this :
http://locus.creacast.com:9001/StBaume_grotte.ogg
I've tried different things but it doesn't seem to work. Streams are never detected.
Solution 1 : Here, i simply tried to check if file exists.
if (file_exists($stream_1)) {
$debug_output_stream_1 = "Le fichier $stream_1 existe.";
$erreur_404_Stream_1 = true;
} else {
$debug_output_stream_1 = "Le fichier $stream_1 n'existe pas.";
$erreur_404_Stream_1 = false;
}
Solutions 2 : I try to detect a 404 error
$file_headers_1 = @get_headers($stream_1);
if($file_headers_1[0] == 'HTTP/1.1 404 Not Found') {
$debug_output_stream_1 = "StBaume_sommet.ogg : L'URL n'existe pas.";
$erreur_404_Stream_1 = true;
}
else {
$debug_output_stream_1 = "StBaume_sommet.ogg : L'URL existe.";
$erreur_404_Stream_1 = false;
}
Do you know how to check if streams exist ?
You are checking the entire status line, including the HTTP version HTTP/1.1
. Most servers return HTTP/1.0
. You need to check the status code only.
if (strpos($file_headers_1[0], '200 OK') === false) {
// error occurred
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.