1

first I'm sorry but my english it's not fluently. I want to stream few huge files to user from another site through my server. Now I'm using for that wget and popen()

$plik = "http://test.mm.pl/100.tmp"; // text file for test - 100 MB
header('Content-Type: application/exe');
header('Content-disposition: attachment; filename="'.basename($plik).'"');
header('Content-Transfer-Encoding: binary');

$fp = popen('wget -qO- '.$plik, 'r');

$bufsize = 1024; // 8192, 4096 i've tried many options
$buff = '';
while( !feof($fp) ) {
   $buff = fread($fp, $bufsize);
   echo $buff;
   flush();
}
pclose($fp);

But transfer rate oscillate between 30-60 kb/s :/ When I try it directly on server :

wget www.somsite.pl/file.tmp

: i've got ~ 500kb/s

What should I do to get better transfer rate ??

sl4sh
  • 51
  • 1
  • 5
  • You are missing `Content-Length` in header. add `header('Content-Length: 1024');` – Leri Sep 25 '12 at 08:34
  • what is the max bandwidth between the server and you? If for example it's a hosted server in a data-center and you are on a standard DSL line then the server will have a much higher bandwidth connection to the 'huge' file than you would have to the server, or the 'huge' file directly. – Loopo Sep 25 '12 at 09:10

1 Answers1

0

You may consider using sendfile it has good performance in compare to wget/popen combination.

or simply send HTTP 302 with URL

Launching wget and connecting it's output with popen is less effective then direct connection using fsockopen.

rkosegi
  • 12,129
  • 5
  • 46
  • 75
  • But file which I want stream doesn't exist on my server, and I don't want to save them on disk. I need something to serve this file 'on the fly' without saving it on server. Code as you see are from : http://stackoverflow.com/questions/4357073/on-the-fly-zipping-streaming-of-large-files-in-php-or-otherwise I can't use 302 redirect :/ In future I need add cookies handling. What I want : http://i47.tinypic.com/140lv7o.png – sl4sh Sep 25 '12 at 09:45
  • But why you want to use wget? fsockopen/file functions has URL wrappers. – rkosegi Sep 25 '12 at 10:13
  • this needn't be wget, I don't know how to do it without wget. I've tried something like that : php script : `$c = curl_init();` `curl_setopt($c, CURLOPT_URL, myurl);` `curl_setopt($c, CURLOPT_RETURNTRANSFER, true);` `curl_exec($c);` `curl_close($c);` and then run it using popen() - but it doesn't work :/ – sl4sh Sep 25 '12 at 10:29