示例#1
0
 function test_hook_modify()
 {
     $this->hook_flags = array();
     $rest = REST_Client::factory('async', array('verbose' => false))->addFireHook(array($this, 'fire_hook_modify'))->addFetchHook(array($this, 'fetch_hook_modify'));
     $r = REST_Request::newInstance()->setProtocol('http')->setHost($this->test_host)->setPort($this->test_port);
     $rest->fire($r->get('/'));
     $resp = $rest->fetch();
     $this->assertEquals('/mymodifiedurl', $r->getUrl());
     $this->assertEquals(404, $resp->code);
 }
示例#2
0
 function test_huge_async()
 {
     $requests = 50000;
     $clients = 150;
     $this->async->setOption('queue_size', $clients);
     $r = REST_Request::newInstance()->setProtocol('http')->setHost($this->test_host)->setPort($this->test_port)->setMethod('GET')->setUrl('/');
     for ($i = 0; $i < $requests; $i++) {
         $this->async->fire($r);
         if ($this->async->overflow()) {
             while ($response = $this->async->fetch()) {
                 $this->assertEquals(200, $response->code);
             }
         }
     }
     while ($response = $this->async->fetch()) {
         $this->assertEquals(200, $response->code);
     }
     $this->assertEquals($requests, $this->async->getInfo('requests'));
 }
示例#3
0
 function test_medium_async()
 {
     $this->async->setOption('queue_size', 3);
     $r = REST_Request::newInstance()->setProtocol('http')->setHost('fr.php.net')->setHttpProxy($this->http_proxy);
     $dom = $this->async->fire($r->get('/dom'));
     $curl = $this->async->fire($r->get('/curl'));
     $strings = $this->async->fire($r->get('/strings'));
     $pcre = $this->async->fire($r->get('/pcre'));
     $xml = $this->async->fire($r->get('/xml'));
     $ftp = $this->async->fire($r->get('/ftp'));
     $sockets = $this->async->fire($r->get('/sockets'));
     $z = array();
     while ($response = $this->async->fetch()) {
         $z[$response->id] = $response->content;
     }
     $this->assertContains('PHP: cURL - Manual', $z[$curl]);
     $this->assertContains('PHP: DOM - Manual', $z[$dom]);
     $this->assertContains('id="book.strings"', $z[$strings]);
     $this->assertContains('PHP: PCRE - Manual', $z[$pcre]);
     $this->assertContains('id="book.xml"', $z[$xml]);
     $this->assertContains('PHP: FTP - Manual', $z[$ftp]);
     $this->assertContains('PHP: Sockets - Manual', $z[$sockets]);
     $this->assertEquals(7, $this->async->getInfo('requests'));
 }
示例#4
0
 public function __construct($host = 'localhost', $port = 80, $options = array())
 {
     $this->request = REST_Request::newInstance()->setProtocol('http')->setHost($host)->setPort($port)->setCurlOptions($options);
     $this->client = REST_Client::factory('sync', array('verbose' => false));
 }