- print doesn't like commas
[m6w6/ext-http] / docs / examples / Parallel_Requests_.php
1 <?php
2 class Pool extends HttpRequestPool
3 {
4 public function __construct()
5 {
6 parent::__construct(
7 new HttpRequest('http://pear.php.net', HTTP_HEAD),
8 new HttpRequest('http://pecl.php.net', HTTP_HEAD)
9 );
10
11 // HttpRequestPool methods socketPerform() and socketSelect() are
12 // protected; one could use this approach to do something else
13 // while the requests are being executed
14 print "Executing requests";
15 for ($i = 0; $this->socketPerform(); $i++) {
16 $i % 10 or print ".";
17 if (!$this->socketSelect()) {
18 throw new HttpException("Socket error!");
19 }
20 }
21 print "\nDone!\n";
22 }
23 }
24
25 try {
26 foreach (new Pool as $r) {
27 echo "Checking ", $r->getUrl(), " reported ", $r->getResponseCode(), "\n";
28 }
29 } catch (HttpException $ex) {
30 print $e;
31 }
32 ?>