Reputation:
I write the php code in iis to serve file for download with speed limit, so i need to use sleep function for the speed limit.
Here, few lines of my code:
set_time_limit(0);
while(!feof($file))
{
echo fread($file, 1024*10);
ob_flush();
flush();
sleep(1);
if (connection_status()!=0)
{
@fclose($file);
exit;
}
}
But the browser say: 'Waiting for mysite'. If i remove sleep(1)
everything is right. I also test in apache and everything is right too.
So I have a problem in IIS with the sleep function.
Upvotes: 0
Views: 277
Reputation: 13995
You need to have your server properly configured for that. TBH you should use something on the server to do that, rather then relying on PHP, the sleep(1);
causes it to send a chunk, pause, send a chunk pause, etc. It does not maintain 10kbps but goes from like 500kbps for a second to 0 kbps for a second, it may average out to 10kbps, but it is not the same and some programs won't treat it correct and may terminate the download. You should look into QoS (How to Limit Download Speeds from my Website on my IIS Windows Server?)
Upvotes: 1
Reputation: 155558
What exactly is the problem with IIS? Note that waiting for 1 second will mean that your script may exceed the timeout limit (this can be as low as 30 seconds) so IIS will kill your script.
If you want to serve large files, I recommend serving them directly from IIS and using IIS' built-in rate limiter rather than via PHP.
See here: http://www.iis.net/configreference/system.applicationhost/sites/site/limits
Upvotes: 0