Streaming local file from PHP while it's been written to by a CURL process
Posted
by Fahim
on Stack Overflow
See other posts from Stack Overflow
or by Fahim
Published on 2010-01-09T20:31:06Z
Indexed on
2010/03/20
7:11 UTC
Read the original article
Hit count: 370
I am creating a simple Proxy server for my website. Why I am not using mod_proxy and mod_cache is a different discussion. Here's the code:
shell_exec("nohup curl --create-dirs -o {$write_path} {$source_url} > /dev/null 2> /dev/null & echo $!");
sleep(1);
$read_speed = 65.5; # 65.5 kb/s download rate
$handle = fopen($write_path, "rb");
$content_type = select_meta_item($headers, 'Content-Type');
$file_size = select_meta_item($headers, 'Content-Length');
send_headers($content_type, $file_size);
flush();
while (!feof($handle))
{
echo fread($handle, round($read_speed * 1024));
flush();
sleep(1);
}
fclose($handle);
Streaming an MP3 doesn't work using this method. Plays in Chrome, but not in Firefox. Initially I'll be using this to stream MP3 files through Long Tail's JW Player. If it all works out, I'll also be using this to send ZIP files.
© Stack Overflow or respective owner