yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

send file and set speed #8439

Closed EngRajabi closed 7 years ago

EngRajabi commented 9 years ago

send file \Yii::$app->response->sendFile('path/to/file.txt')->send(); bute send file with speed \Yii::$app->response->sendFile('path/to/file.txt',900)->send(); add property set speed

EngRajabi commented 9 years ago

in many projects , there are some send file that are needed to set speed send file

lynicidn commented 9 years ago

http://www.nginxtips.com/how-to-limit-nginx-download-speed/

EngRajabi commented 9 years ago

bute im used to \Yii::$app->response->sendFile()->send(); not used popular nginx

cebe commented 9 years ago

can't the nginx limit be combined with sendFile() ? Not sure if/how Yii could control download speed...

alexandernst commented 9 years ago

Maybe http://stackoverflow.com/questions/4002106/limit-download-speed-using-php ? Doesn't sound as a bad idea if you can control the timeout of each PHP process. And if not, Yii could ignore the speed limit (or throw a warning/error)

usualdesigner commented 9 years ago

It should be implemented on the web-server's side IMO.

alexandernst commented 9 years ago

@usualdesigner Yii is on the server side. Anyways, I get what you mean: the web server should take care about that. There is a problem with that: you can't programaticaly control how the webserver sends the file.

lynicidn commented 9 years ago
 sleep(1);  

it's not true for highload

samdark commented 9 years ago

@lynicidn ???

lynicidn commented 9 years ago

@samdark script work up time

lynicidn commented 9 years ago

set_time_limit(0) - not true :)

samdark commented 9 years ago

Can't get what you're trying to say. Sorry.

lynicidn commented 9 years ago

@samdark тот путь что черех пхп, он работает через sleep, что приостонавливает работу скрипта, т.е. пхп занят, а скрипт в паузе, да и вообще set time limit это не настройка для отдачи файлов пачками, это костыль для этого

samdark commented 9 years ago

А, ну это понятно.

SamMousa commented 7 years ago

I don't think this should be in the core.

Extensions could be created that support a specific sending backend (nginx, apache, PHP) and implement the limit there.

Note that implementing this in PHP could be a bad idea because the webserver tends to buffer the response which could cause weird results like getting lower throughput. For example if the webserver buffers 10 seconds of ratelimited output and then sends that to the client at once, who cannot handle that data fast enough, then the effective download speed will be much lower than intended.

samdark commented 7 years ago

Agree.