Note that in the example when it says "Send file with approximately 20 kbyte/s." that is only an upper bound. The file could still be sent at a lesser speed (e.g. 10 kb/s) if the client, network, or server, cannot handle the amount.
http_throttle
(PECL pecl_http >= 0.10.0)
http_throttle — HTTP throttling
Описание
void http_throttle
([ float $sec
[, int $bytes = 40960
]] )
Sets the throttle delay and send buffer size.
Забележка: Тази функция би трябвало да се използва в комбинация с http_send_data(), http_send_file() и http_send_stream().
Забележка: Предоставя основен потискащ механизъм, който ще отстъпи предимството на текущия процес или нишка докато съответният обект не се изпрати напълно.
Забележка: Възможно е това да не работи според очакваното със следните SAPI(та): FastCGI.
Параметри
- sec
-
seconds to sleep after each chunk sent
- bytes
-
the chunk size in bytes
Примери
Example #1 A http_throttle() example
Send file with approximately 20 kbyte/s.
<?php
// ~ 20 kbyte/s
# http_throttle(1, 20000);
# http_throttle(0.5, 10000);
http_throttle(0.1, 2000);
http_send_file('document.pdf');
?>
Вж. също
- http_send_data() - Send arbitrary data
- http_send_file() - Send file
- http_send_stream() - Send stream
- класът HttpResponse, ако използвате PHP 5.1.0 или по-нова
dr dot sane at gmail dot com
19-Mar-2011 01:24
