initial commit
[m6w6/m6w6.github.io] / _posts / 2005-06-07-httprequestpool-in-peclhttp.md
1 ---
2 title: HttpRequestPool in PECL::HTTP
3 author: m6w6
4 tags:
5 - PHP
6 ---
7
8 I just checked in a first working version of HttpRequestPool into CVS.
9 It's curl_multi that's doing its job underneath and is used tp send several
10 HttpRequests at once.
11 ```php
12 $urls = array(
13 'http://www.php.net/',
14 'http://pear.php.net/',
15 'http://pecl.php.net/'
16 );
17
18 $pool = new HttpRequestPool;
19 foreach ($urls as $url) {
20 $pool->attach(new HttpRequest($url, HTTP_METH_HEAD));
21 }
22
23 try {
24 $pool->send();
25 foreach ($pool as $r) {
26 $status = $r->getResponseCode();
27 printf("%-20s is %sn",
28 $r->getUrl(),
29 $status == 200 ? "ALIVE" : "NOT OK ($status)"
30 );
31 }
32 } catch (HttpException $ex) {
33 echo $ex;
34 }
35 ```