Turn off buffering!?

#1
Hello ,
I wrote a code in php to read a file from remote server and send the content to a user , something like a proxy.
-----
PHP:
$fp = fsockopen('address.com', 80, $errno, $errstr);
...//some code to send headers to http://address.com/ server to get 1.rar file.
fputs($fp, $headers);
fflush($fp);
while (!feof($fp))
{
	echo fgets($fp, '1024');
	ob_end_flush();
}
----
for example if 1.rar is about 50meg , and a user have 100KB connection ,when he start to download that file , the server read that file with 10 MB speed and send it to user.That cause server to read all file and buffer it and send it to user , and get more memory.
I can't limit the script speed , because my users have different speed , but I want my script read data and wait until the data send to user and then read the next segment of data.
Is there any config in litespeed to correct this for me?
Thanks.
 
#3
same problem

hi ,
I have the same problem as f4nny does.
I monitor download script and figure out that for example , a user download about 10 meg in 1 min , and the server cahce about 335 meg! for a file with 65 meg size . That's horrible!
You mean there is no option to control this!?
I think server runs my script and caches data before deliver to my user and if my user stopping to download , the cache will be wasted.
i adapted my code from f4nny's code :
PHP:
<?php
$name=rand().'.txt';
$hand=fopen($name,'w');
$fp = fsockopen('address.com', 80, $errno, $errstr);
...//some code to send headers to http://address.com/ server to get 1.rar file.
fputs($fp, $headers);
fflush($fp);
while (!feof($fp))
{
    echo $b= fgets($fp, '1024');
    fwrite($hand,$b);
    ob_end_flush();
}  
?>
 
Last edited:
Top