0

I'm trying to test to see if a .flv video stream exists on my page before deciding if to display flowplayer or not. I thought i'd have a go at looking at the file headers to see if it was found or not (I dunno if this will actuatlly work)....using the following function:

function StreamRunning(){

    $file_headers = @get_headers('http://12.34.56.789:1234/stream.flv');
    if($file_headers[0] == 'HTTP/1.1 404 Not Found') {   // HTTP/1.1 200 OK
        return false;
    }
    else {
        return true;
    }

}

To test things i've hard coded in the URL of the stream. In reality this will be the public IP address of my computer streaming the video from VLC player, but for this demo i've replaced it with 12.34...etc..

The problem I'm getting is this function seems to cause a white page of death error, giving me no clue what's wrong. Not even anything in my log file. I guess there's two questions really,

  1. Is there something wrong with my function? Does get_headers not accept I/P addresses like that?
  2. Is there a better way I should be doing this anyway?

Thanks in advance!

Update: 13-3-11 11:03 (GMT) - If the .flv stream is actuatlly there the page loads fine, if the .flv stream is missing get_headers causes a white screen of death,even with all error reporting enabled, nothig in the log.

Dan Twining
  • 640
  • 4
  • 17
  • 30
  • 3
    The first step must **always** be removing the `@` error suppression operator. – Pekka Mar 13 '11 at 10:29
  • 3
    The second step is to enable error reporting: e.g. `error_reporting(E_ALL);` that should give you a meaningful error message to work with. – Pekka Mar 13 '11 at 10:41
  • I added what you suggested, but it still causing a blank white screen error. If I replace the URL in the get_headers line with something else (such as http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png) it works ok. I def added in error_reporting ok because it was showing up $_GET variables that wern't defined which it never did before. – Dan Twining Mar 13 '11 at 10:54
  • Ok, interestingly, If I enable my video stream the page loads fine, the problem is if the stream is not there get_headers causes white screen of death! – Dan Twining Mar 13 '11 at 11:01
  • @Dan that is normally where error reporting is supposed to kick in, that's why I say it's strange. – Pekka Mar 13 '11 at 11:02

3 Answers3

1

When you call get_headers($url) it performs GET query to provided URL and then returns recieved headers. For plain documents (like pages, images, etc.) it performs quickly. When you request video stream it trying to receive all document but can not becouse it is interrupted by timeout or something like that.

Try to use Curl (as recommended by @sexyprout) but use HEAD request instead of GET — it retrieves only headers without response contents:

curl_setopt($ch, CURLOPT_NOBODY, 1);
Helios
  • 86
  • 3
  • aaahh, that sounds about right. I've tried to modify @sexyprout 's example, but it's still returning blank. to confirm I replaced the second line in the example to your line above? I'm not sure how to place code into responses! I'll have a go.... `$ch = curl_init('http://12.34.56.789:1234/stream.flv'); curl_setopt($ch, CURLOPT_NOBODY, 1); $c = curl_exec($ch); echo curl_getinfo($ch, CURLINFO_HTTP_CODE); ` – Dan Twining Mar 13 '11 at 12:44
  • Well, I tried adding in what you suggested but it still gives me the white screen of death. `$ch = curl_init('http://12.34.56.789:1234/Secret.flv'); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); $c = curl_exec($ch); echo curl_getinfo($ch, CURLINFO_HTTP_CODE); ` Any further ideas? – Dan Twining Mar 16 '11 at 00:09
0

Try to call this function without @ before it an — you will see what's wrong.

Helios
  • 86
  • 3
  • Hi, Sorry, I should have added that I tried removing the @ and it made no difference. It's definatly that line causing the problem though because I replaced $file_headers = @get_headers('http://12.34.56.789:1234/stream.flv'); with $file_headers = get_headers('http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png'); and it worked fine. – Dan Twining Mar 13 '11 at 10:38
0

Maybe this alternative way could work:

$ch = curl_init('http://12.34.56.789:1234/stream.flv');
curl_setopt($ch, CURLOPT_HEADER, 1);
$c = curl_exec($ch);

echo curl_getinfo($ch, CURLINFO_HTTP_CODE);
seriousdev
  • 7,519
  • 8
  • 45
  • 52
  • I tried it and it just does the same thing....well, I get nothing. If I changed the actualy path to "http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png" I get a response! – Dan Twining Mar 13 '11 at 10:45