當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Client::setCurlMulti方法代碼示例

本文整理匯總了PHP中Guzzle\Http\Client::setCurlMulti方法的典型用法代碼示例。如果您正苦於以下問題:PHP Client::setCurlMulti方法的具體用法?PHP Client::setCurlMulti怎麽用?PHP Client::setCurlMulti使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Guzzle\Http\Client的用法示例。


在下文中一共展示了Client::setCurlMulti方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testSavesResponsesInCache

 /**
  * @covers Guzzle\Http\Plugin\CachePlugin::onRequestSent
  * @covers Guzzle\Http\Plugin\CachePlugin::onRequestBeforeSend
  * @covers Guzzle\Http\Plugin\CachePlugin::saveCache
  * @covers Guzzle\Http\Plugin\CachePlugin::getCacheKey
  * @covers Guzzle\Http\Plugin\CachePlugin::canResponseSatisfyRequest
  */
 public function testSavesResponsesInCache()
 {
     // Send a 200 OK script to the testing server
     $this->getServer()->enqueue(array("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ndata", "HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ntest"));
     // Create a new Cache plugin
     $plugin = new CachePlugin($this->adapter);
     $client = new Client($this->getServer()->getUrl());
     $client->setCurlMulti(new \Guzzle\Http\Curl\CurlMulti());
     $client->getEventDispatcher()->addSubscriber($plugin);
     $request = $client->get();
     $request->send();
     // Calculate the cache key like the cache plugin does
     $key = $plugin->getCacheKey($request);
     // Make sure that the cache plugin set the request in cache
     $this->assertNotNull($this->adapter->fetch($key));
     // Clear out the requests stored on the server to make sure we didn't send a new request
     $this->getServer()->flush();
     // Test that the request is set manually
     // The test server has no more script data, so if it actually sends a
     // request it will fail the test.
     $this->assertEquals($key, $plugin->getCacheKey($request));
     $request->setState('new');
     $request->send();
     $this->assertEquals('data', $request->getResponse()->getBody(true));
     // Make sure a request wasn't sent
     $this->assertEquals(0, count($this->getServer()->getReceivedRequests(false)));
 }
開發者ID:jsnshrmn,項目名稱:Suma,代碼行數:34,代碼來源:CachePluginTest.php

示例2: testTransfersBatches

 public function testTransfersBatches()
 {
     $client = new Client('http://localhost:123');
     $request = $client->get();
     $multi = $this->getMock('Guzzle\\Http\\Curl\\CurlMultiInterface');
     $client->setCurlMulti($multi);
     $multi->expects($this->once())->method('add')->with($request);
     $multi->expects($this->once())->method('send');
     $batch = new BatchRequestTransfer(2);
     $batch->transfer(array($request));
 }
開發者ID:jsnshrmn,項目名稱:Suma,代碼行數:11,代碼來源:BatchRequestTransferTest.php

示例3: testTrimsDownMaxHandleCount

 public function testTrimsDownMaxHandleCount()
 {
     $this->getServer()->flush();
     $this->getServer()->enqueue(array("HTTP/1.1 307 OK\r\nLocation: /foo\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 307 OK\r\nLocation: /foo\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 307 OK\r\nLocation: /foo\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 307 OK\r\nLocation: /foo\r\nContent-Length: 0\r\n\r\n", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"));
     $client = new Client($this->getServer()->getUrl());
     $client->setCurlMulti(new CurlMultiProxy(2));
     $request = $client->get();
     $request->send();
     $this->assertEquals(200, $request->getResponse()->getStatusCode());
     $handles = $this->readAttribute($client->getCurlMulti(), 'handles');
     $this->assertEquals(2, count($handles));
 }
開發者ID:ludichrislyts,項目名稱:fieldWork,代碼行數:12,代碼來源:CurlMultiProxyTest.php

示例4: testTransfersBatches

 public function testTransfersBatches()
 {
     $client = new Client('http://127.0.0.1:123');
     $request = $client->get();
     // For some reason... PHP unit clones the request, which emits a request.clone event. This causes the
     // 'sorted' property of the event dispatcher to contain an array in the cloned request that is not present in
     // the original.
     $request->dispatch('request.clone');
     $multi = $this->getMock('Guzzle\\Http\\Curl\\CurlMultiInterface');
     $client->setCurlMulti($multi);
     $multi->expects($this->once())->method('add')->with($request);
     $multi->expects($this->once())->method('send');
     $batch = new BatchRequestTransfer(2);
     $batch->transfer(array($request));
 }
開發者ID:alvarobfdev,項目名稱:applog,代碼行數:15,代碼來源:BatchRequestTransferTest.php

示例5: testCatchesExceptionsBeforeSendingCurlMulti

 /**
  * @covers Guzzle\Http\Curl\CurlMulti
  * @expectedException RuntimeException
  * @expectedExceptionMessage Testing!
  */
 public function testCatchesExceptionsBeforeSendingCurlMulti()
 {
     $client = new Client($this->getServer()->getUrl());
     $multi = new CurlMulti();
     $client->setCurlMulti($multi);
     $multi->getEventDispatcher()->addListener(CurlMulti::BEFORE_SEND, function () {
         throw new \RuntimeException('Testing!');
     });
     $client->get()->send();
 }
開發者ID:MicroSDHC,項目名稱:justinribeiro.com-examples,代碼行數:15,代碼來源:CurlMultiTest.php

示例6: testCatchesExceptionsBeforeSendingSingleRequest

 public function testCatchesExceptionsBeforeSendingSingleRequest()
 {
     $client = new Client($this->getServer()->getUrl());
     $multi = new CurlMulti();
     $client->setCurlMulti($multi);
     $request = $client->get();
     $request->getEventDispatcher()->addListener('request.before_send', function () {
         throw new \RuntimeException('Testing!');
     });
     try {
         $request->send();
         $this->fail('Did not throw');
     } catch (\RuntimeException $e) {
         // Ensure it was removed
         $this->assertEquals(0, count($multi));
     }
 }
開發者ID:biribogos,項目名稱:wikihow-src,代碼行數:17,代碼來源:CurlMultiTest.php

示例7: testAllowsCustomCurlMultiObjects

 public function testAllowsCustomCurlMultiObjects()
 {
     $mock = $this->getMock('Guzzle\\Http\\Curl\\CurlMulti', array('add', 'send'));
     $mock->expects($this->once())->method('add')->will($this->returnSelf());
     $mock->expects($this->once())->method('send')->will($this->returnSelf());
     $client = new Client();
     $client->setCurlMulti($mock);
     $request = $client->get();
     $request->setResponse(new Response(200), true);
     $client->send($request);
 }
開發者ID:carlesgutierrez,項目名稱:libreobjet.org,代碼行數:11,代碼來源:ClientTest.php


注:本文中的Guzzle\Http\Client::setCurlMulti方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。