views:

41

answers:

3

I have a url like http://localhost:8020/stream.flv

On request to my php sctipt I want to return (be something like a proxy) all data I can get from that URL (so I mean my php code should get data from that url and give it to user) and my header and my beginning of file.

So I have my header and some data I want to write in the beginning of response like

# content headers
        header("Content-Type: video/x-flv");        
        # FLV file format header
        if($seekPos != 0) 
        {
        print('FLV');
        print(pack('C', 1));
        print(pack('C', 1));
        print(pack('N', 9));
        print(pack('N', 9));
    }

How to do such thing?

A: 

See the manual entries for fopen and fread.

Artefacto
A: 

I've accomplished this using libcurl,

$url = 'http://localhost:8020/stream.flv';
$ch = curl_init();
curl_exec($ch);
curl_close($ch);
alxp
but problem is on that side localhost:8020/stream.flv the stream is live and so infinit... so Any notes for such case?
Blender
+1  A: 

Here's the code I used to do something very similar, I also forwarded all headers from the original flv to the end user but you can just remove that section if you want to set your own.

$video = fopen(URL, "rb");

// Forward headers, $http_response_header is populated by fopen call
foreach ($http_response_header AS $header) {
    header($header);
}

// Output contents of flv
while (!feof($video)) {
    print (fgets($video));
}

fclose($video);
JoeR
but problem is on that side http://localhost:8020/stream.flv the stream is live and so infinit... so Any notes for such case?
Blender
Hmmm fopen doesn't download the whole file, and feof will in theory continue reading the file until the end - ie never in the case of a stream? At least that's what I'm thinking but could well be wrong - give it a try!
JoeR