extesion deps
[m6w6/ext-http] / tests / requestpool001.phpt
index a65ada45894b0105b33d3d5dbea0f1317f0e29e8..ff91a406801c2a2037c90256dc4969b851bbc4cc 100644 (file)
@@ -7,19 +7,13 @@ include 'skipif.inc';
 --FILE--
 <?php
 
-use http\request\Factory as HttpRequestFactory;
-use http\request\Pool as HttpRequestPool;
-use http\request\Method as HttpRequestMethod;
-use http\RequestException as HttpRequestException;
-use http\SocketException as HttpSocketException;
-
 echo "-TEST\n";
 
 set_time_limit(0);
 ini_set('error_reporting', E_ALL);
 ini_set('html_errors', 0);
 
-class Pool extends HttpRequestPool
+class Pool extends \http\Curl\Client\Pool
 {
        private $all;
        private $rem;
@@ -51,9 +45,7 @@ class Pool extends HttpRequestPool
                
                foreach ($now as $url => $file) {
                        $this->attach(
-                               $this->factory->createRequest(
-                                       $url,
-                                       HttpRequestMethod::GET,
+                               $this->factory->createClient(
                                        array(
                                                'redirect'      => 5,
                                                'compress'  => GZIP,
@@ -61,13 +53,13 @@ class Pool extends HttpRequestPool
                                                'connecttimeout' => TOUT,
                                                'lastmodified' => is_file($file)?filemtime($file):0
                                        )
-                               )
+                               )->setRequest(new http\Client\Request("GET", $url))
                        );
                }
                
                while ($this->once()) {
                        if (!$this->wait()) {
-                               throw new HttpSocketException;
+                               throw new http\Exception;
                        }
                }
        }
@@ -76,18 +68,23 @@ class Pool extends HttpRequestPool
        {
                try {
                        $rc = parent::once();
-               } catch (HttpRequestException $x) {
+               } catch (http\Exception $x) {
                        // a request may have thrown an exception,
                        // but it is still save to continue
                        echo $x->getMessage(), "\n";
                }
                
-               foreach ($this->getFinishedRequests() as $r) {
+               foreach ($this->getFinished() as $r) {
                        $this->detach($r);
                        
-                       $u = $r->getUrl();
-                       $c = $r->getResponseCode();
-                       $b = $r->getResponseBody();
+                       $u = $r->getRequest()->getRequestUrl();
+                       $c = $r->getResponseMessage()->getResponseCode();
+            try {
+                       $b = $r->getResponseMessage()->getBody();
+            } catch (\Exception $e) {
+                echo $e->getMessage(), "\n";
+                $b = "";
+            }
                        
                        printf("%d %s %d\n", $c, $u, strlen($b));
                        
@@ -98,9 +95,7 @@ class Pool extends HttpRequestPool
                        if ($a = each($this->rem)) {
                                list($url, $file) = $a;
                                $this->attach(
-                                       $this->factory->createRequest(
-                                               $url,
-                                               HttpRequestMethod::GET,
+                                       $this->factory->createClient(
                                                array(
                                                        'redirect'      => 5,
                                                        'compress'      => GZIP,
@@ -108,7 +103,7 @@ class Pool extends HttpRequestPool
                                                        'connecttimeout' => TOUT,
                                                        'lastmodified' => is_file($file)?filemtime($file):0
                                                )
-                                       )
+                                       )->setRequest(new http\Client\Request("GET", $url))
                                );
                        }
                }
@@ -117,12 +112,12 @@ class Pool extends HttpRequestPool
 }
 
 define('GZIP', true);
-define('TOUT', 50);
+define('TOUT', 300);
 define('RMAX', 10);
 chdir(__DIR__);
 
 $time = microtime(true);
-$factory = new HttpRequestFactory(array("driver" => "curl", "requestPoolClass" => "Pool"));
+$factory = new http\Client\Factory(array("driver" => "curl", "clientPoolClass" => "Pool"));
 $factory->createPool()->run($factory);
 printf("Elapsed: %0.3fs\n", microtime(true)-$time);