本文整理汇总了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)));
}
示例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));
}
示例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));
}
示例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));
}
示例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();
}
示例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));
}
}
示例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);
}