Request Pooling

pecl_http also inherits cURL’s support for request pooling, or sending and processing multiple requests in parallel. Like other features, pecl_http implements it in a more succinct fashion. Oddly enough, it is one feature that is limited to pecl_http’s object-oriented API and has no equivalent in its procedural API. It is implemented in the form of the HttpRequestPool class.

<?php
$request1 = new HttpRequest;

// configure $request1
$request2 = new HttpRequest;

// configure $request2
$request3 = new HttpRequest;

// configure $request3
$pool = new HttpRequestPool($request1, $request2);
$pool->attach($request3);
$pool->send();
?>
  • The HttpRequestPool constructor accepts a variable number of arguments, all of which should be preconfigured HttpRequest instances.
  • Request instances can also be added via the attach method of the HttpRequestPool class.
  • send is called on the pool instance to transmit all requests and blocks until all responses are received. Once complete, all request instances contain their respective sets of response data as if they had been sent individually.

© pecl_http PECL Extension — Web Scraping

>>> Back to TABLE OF CONTENTS <<<
Category: Article | Added by: Marsipan (31.08.2014)
Views: 398 | Rating: 0.0/0
Total comments: 0
avatar