Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p><strong>DISCLAIMER:</strong> This answer links an open-source project with which I'm involved. There. You've been warned.</p> </blockquote> <p>The <a href="https://github.com/rdlowrey/Artax" rel="nofollow">Artax HTTP client</a> is a socket-based HTTP library that (among other things) offers custom control over the number of concurrent open socket connections to individual hosts while making multiple asynchronous HTTP requests.</p> <p>Limiting the number of concurrent connections is easily accomplished. Consider:</p> <pre><code>&lt;?php use Artax\Client, Artax\Response; require dirname(__DIR__) . '/autoload.php'; $client = new Client; // Defaults to max of 8 concurrent connections per host $client-&gt;setOption('maxConnectionsPerHost', 2); $requests = array( 'so-home' =&gt; 'http://stackoverflow.com', 'so-php' =&gt; 'http://stackoverflow.com/questions/tagged/php', 'so-python' =&gt; 'http://stackoverflow.com/questions/tagged/python', 'so-http' =&gt; 'http://stackoverflow.com/questions/tagged/http', 'so-html' =&gt; 'http://stackoverflow.com/questions/tagged/html', 'so-css' =&gt; 'http://stackoverflow.com/questions/tagged/css', 'so-js' =&gt; 'http://stackoverflow.com/questions/tagged/javascript' ); $onResponse = function($requestKey, Response $r) { echo $requestKey, ' :: ', $r-&gt;getStatus(); }; $onError = function($requestKey, Exception $e) { echo $requestKey, ' :: ', $e-&gt;getMessage(); } $client-&gt;requestMulti($requests, $onResponse, $onError); </code></pre> <p><em>IMPORTANT</em>: In the above example the <code>Client::requestMulti</code> method is making all the specified requests <strong>asynchronously</strong>. Because the per-host concurrency limit is set to <code>2</code>, the client will open up new connections for the first two requests and subsequently reuse those same sockets for the other requests, queuing requests until one of the two sockets become available.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload