- add missing support for raw post data (HttpRequest)
[m6w6/ext-http] / docs / examples / Parallel_Requests_.php
diff --git a/docs/examples/Parallel_Requests_.php b/docs/examples/Parallel_Requests_.php
new file mode 100644 (file)
index 0000000..e1eb88f
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+class Pool extends HttpRequestPool
+{
+       public function __construct()
+       {
+               parent::__construct(
+                       new HttpRequest('http://pear.php.net', HTTP_HEAD),
+                       new HttpRequest('http://pecl.php.net', HTTP_HEAD)
+               );
+
+               // HttpRequestPool methods socketPerform() and socketSelect() are
+               // protected;  one could use this approach to do something else
+               // while the requests are being executed
+               print "Executing requests";
+               for ($i = 0; $this->socketPerform(); $i++) {
+                       $i % 3 or print ".";
+                       if (!$this->socketSelect()) {
+                               throw new HttpException("Socket error!");
+                       }
+               }
+               print "\nDone!\n";
+       }
+}
+
+try {
+       foreach (new Pool as $r) {
+               print "Checking ", $r->getUrl(), " reported ", $r->getResponseCode(), "\n";
+       }
+} catch (HttpException $ex) {
+       print $e;
+}
+?>