- add HttpRequestPool::getFinishedRequests(), so now it's possible to process finishe...
[m6w6/ext-http] / tests / HttpRequestPool_002.phpt
diff --git a/tests/HttpRequestPool_002.phpt b/tests/HttpRequestPool_002.phpt
new file mode 100644 (file)
index 0000000..053f1f6
--- /dev/null
@@ -0,0 +1,49 @@
+--TEST--
+extending HttpRequestPool
+--SKIPIF--
+<?php
+include 'skip.inc';
+checkcls('HttpRequestPool');
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+
+class MyPool extends HttpRequestPool
+{
+       public function send()
+       {
+               while ($this->socketPerform()) {
+                       $this->handleRequests();
+                       if (!$this->socketSelect()) {
+                               throw new HttpSocketException;
+                       }
+               }
+               $this->handleRequests();
+       }
+       
+       private function handleRequests()
+       {
+               echo ".";
+               foreach ($this->getFinishedRequests() as $r) {
+                       echo "=", $r->getResponseCode(), "=";
+                       $this->detach($r);
+               }
+       }
+}
+
+$pool = new MyPool(
+    new HttpRequest('http://www.php.net/', HTTP_METH_HEAD),
+    new HttpRequest('http://at.php.net/', HTTP_METH_HEAD),
+    new HttpRequest('http://de.php.net/', HTTP_METH_HEAD),
+    new HttpRequest('http://ch.php.net/', HTTP_METH_HEAD)
+);
+
+$pool->send();
+
+echo "\nDone\n";
+?>
+--EXPECTREGEX--
+.+TEST
+\.+=200=\.+=200=\.+=200=\.+=200=
+Done