Skip to content

Instantly share code, notes, and snippets.

@stefanocudini
Created March 30, 2012 17:36
Show Gist options
  • Select an option

  • Save stefanocudini/2253231 to your computer and use it in GitHub Desktop.

Select an option

Save stefanocudini/2253231 to your computer and use it in GitHub Desktop.
php readfile with limit bitrate
<?php
$file = $_SERVER['QUERY_STRING'];
header("Content-length: ".filesize($file));
header("Content-type: ".mime_content_type($file));
readfileLimit($file);
function readfileLimit($file, $limit='20k')
{
$bsize = 1024;
$f = popen("pv -B $bsize -L $limit '$file'",'r') or return false;
while(!feof($f))
{
echo fread($f, $bsize);
flush();
}
fclose($f);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment