<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>HTTP throttling</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.http-send-stream.html">http_send_stream</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.http-build-str.html">http_build_str</a></div> <div class="up"><a href="ref.http.html">HTTP Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.http-throttle" class="refentry"> <div class="refnamediv"> <h1 class="refname">http_throttle</h1> <p class="verinfo">(PECL pecl_http >= 0.10.0)</p><p class="refpurpose"><span class="refname">http_throttle</span> — <span class="dc-title">HTTP throttling</span></p> </div> <div class="refsect1 description" id="refsect1-function.http-throttle-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>http_throttle</strong></span> ( <span class="methodparam"><span class="type">float</span> <code class="parameter">$sec</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$bytes</code><span class="initializer"> = 40960</span></span> ] )</div> <p class="para rdfs-comment"> Sets the throttle delay and send buffer size. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">This function should be used in conjunction with <span class="function"><a href="function.http-send-data.html" class="function">http_send_data()</a></span>, <span class="function"><a href="function.http-send-file.html" class="function">http_send_file()</a></span> and <span class="function"><a href="function.http-send-stream.html" class="function">http_send_stream()</a></span>.</span></p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">Provides a basic throttling mechanism, which will yield the current process or thread until the entity has been completely sent.</span></p></blockquote> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> This may not work as expected with the following SAPI(s): FastCGI. </p> </p></blockquote> </div> <div class="refsect1 parameters" id="refsect1-function.http-throttle-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">sec</code></em></span> <dd> <p class="para"> seconds to sleep after each chunk sent </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">bytes</code></em></span> <dd> <p class="para"> the chunk size in bytes </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 examples" id="refsect1-function.http-throttle-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4375"> <p><strong>Example #1 A <span class="function"><strong>http_throttle()</strong></span> example</strong></p> <div class="example-contents"><p> Send file with approximately 20 kbyte/s. </p></div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// ~ 20 kbyte/s<br /># http_throttle(1, 20000);<br /># http_throttle(0.5, 10000);<br /></span><span style="color: #0000BB">http_throttle</span><span style="color: #007700">(</span><span style="color: #0000BB">0.1</span><span style="color: #007700">, </span><span style="color: #0000BB">2000</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">http_send_file</span><span style="color: #007700">(</span><span style="color: #DD0000">'document.pdf'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.http-throttle-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.http-send-data.html" class="function" rel="rdfs-seeAlso">http_send_data()</a> - Send arbitrary data</span></li> <li class="member"> <span class="function"><a href="function.http-send-file.html" class="function" rel="rdfs-seeAlso">http_send_file()</a> - Send file</span></li> <li class="member"> <span class="function"><a href="function.http-send-stream.html" class="function" rel="rdfs-seeAlso">http_send_stream()</a> - Send stream</span></li> <li class="member">the <a href="class.httpresponse.html" class="link"> <a href="class.httpresponse.html" class="classname">HttpResponse</a></a> class if you are using PHP 5.1.0 and above</li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.http-send-stream.html">http_send_stream</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.http-build-str.html">http_build_str</a></div> <div class="up"><a href="ref.http.html">HTTP Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>