本文整理匯總了PHP中Requests::request_multiple方法的典型用法代碼示例。如果您正苦於以下問題:PHP Requests::request_multiple方法的具體用法?PHP Requests::request_multiple怎麽用?PHP Requests::request_multiple使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Requests
的用法示例。
在下文中一共展示了Requests::request_multiple方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: batchLoad
/**
* @inheritDoc
*/
public function batchLoad($requests)
{
/** @var IApiRequest[] $originals */
$originals = [];
$batchRequests = [];
foreach ($requests as $i => $request) {
if ($request instanceof IApiRequest) {
$originals[$i] = $request;
$reqDet = $request->getRequestDetail();
$batchReq = ['url' => $reqDet->getUrl(), 'headers' => $this->_buildHeaders($reqDet), 'data' => $this->_buildData($reqDet), 'type' => $reqDet->getMethod(), 'options' => $reqDet->getOptions(), 'cookies' => []];
$batchRequests[$i] = $batchReq;
}
}
try {
$responses = \Requests::request_multiple($batchRequests);
foreach ($responses as $id => $response) {
$originals[$id]->setRawResult($this->_getResult($response));
}
return $this;
} catch (\Exception $e) {
$this->_handleException($e);
}
}
示例2: multiRequest
/**
* @inheritdoc
*/
public function multiRequest(array $urls)
{
$requests = array();
foreach ($urls as $urlName => $urlData) {
if (is_string($urlData)) {
$urlData = array($urlData, array());
}
$urlOptions = new Options($urlData[1]);
$method = $urlOptions->get('method', 'GET', 'up');
$args = $urlOptions->get('args');
$url = 'GET' === $method ? Url::addArg((array) $args, $urlData[0]) : $urlData[0];
$args = 'GET' !== $method ? $args : array();
$requests[$urlName] = array('url' => $url, 'headers' => $urlOptions->getHeaders(), 'data' => $args, 'type' => $method, 'options' => $this->_getClientOptions($urlOptions));
}
$httpResults = \Requests::request_multiple($requests);
/** @var string $resName */
/** @var \Requests_Response $httpResult */
$result = array();
foreach ($httpResults as $resName => $httpResult) {
$result[$resName] = array($httpResult->status_code, $httpResult->headers->getAll(), $httpResult->body);
}
return $result;
}
示例3: testMultipleToFile
public function testMultipleToFile()
{
$requests = array('get' => array('url' => httpbin('/get'), 'options' => array('filename' => tempnam(sys_get_temp_dir(), 'RLT'))), 'post' => array('url' => httpbin('/post'), 'type' => Requests::POST, 'data' => 'test', 'options' => array('filename' => tempnam(sys_get_temp_dir(), 'RLT'))));
$responses = Requests::request_multiple($requests, $this->getOptions());
// GET request
$contents = file_get_contents($requests['get']['options']['filename']);
$result = json_decode($contents, true);
$this->assertEquals(httpbin('/get'), $result['url']);
$this->assertEmpty($result['args']);
unlink($requests['get']['options']['filename']);
// POST request
$contents = file_get_contents($requests['post']['options']['filename']);
$result = json_decode($contents, true);
$this->assertEquals(httpbin('/post'), $result['url']);
$this->assertEquals('test', $result['data']);
unlink($requests['post']['options']['filename']);
}
示例4: us_fan_counts
//.........這裏部分代碼省略.........
$requests[$network] = array('url' => "http://api.vk.com/method/groups.getById?gid=" . $id . "&fields=members_count");
}
break;
case 'pinterest':
$username = UltimateSocialDeux::opt('us_pinterest_username');
if ($username) {
$requests[$network] = array('url' => 'http://www.pinterest.com/' . $username . '/');
}
break;
case 'flickr':
$id = UltimateSocialDeux::opt('us_flickr_id');
$api = UltimateSocialDeux::opt('us_flickr_api');
if ($id && $api) {
$requests[$network] = array('url' => "https://api.flickr.com/services/rest/?method=flickr.groups.getInfo&api_key=" . $api . "&group_id=" . $id . "&format=json&nojsoncallback=1");
}
break;
case 'feedpress':
$manual = intval(UltimateSocialDeux::opt('us_feedpress_manual', 0));
$url = UltimateSocialDeux::opt('us_feedpress_url');
if (filter_var($url, FILTER_VALIDATE_URL)) {
$requests[$network] = array('url' => $url);
}
if ($manual) {
$option[$network]['count'] = $manual;
$json[$network]['count'] = $manual;
}
break;
default:
unset($option[$network]);
unset($json[$network]);
break;
}
}
$responses = !empty($requests) ? Requests::request_multiple($requests) : die('No requests sent.');
foreach ($responses as $network => $data) {
switch ($network) {
case 'facebook':
if (isset($responses[$network]->body)) {
$content = $responses[$network]->body;
if ($ajax_debug) {
print_r($content);
}
$content = json_decode($content, true);
$option[$network]['count'] = intval($content['likes']);
$json[$network]['count'] = intval($content['likes']);
}
break;
case 'twitter':
case 'soundcloud':
case 'dribbble':
if (isset($responses[$network]->body)) {
$content = $responses[$network]->body;
if ($ajax_debug) {
print_r($content);
}
$content = json_decode($content, true);
$option[$network]['count'] = intval($content['followers_count']);
$json[$network]['count'] = intval($content['followers_count']);
}
break;
case 'google':
if (isset($responses[$network]->body)) {
$content = $responses[$network]->body;
if ($ajax_debug) {
print_r($content);
}
示例5: request_multiple
/**
* Send multiple HTTP requests simultaneously
*
* @see Requests::request_multiple()
*
* @param array $requests Requests data (see {@see Requests::request_multiple})
* @param array $options Global and default options (see {@see Requests::request})
* @return array Responses (either Requests_Response or a Requests_Exception object)
*/
public function request_multiple($requests, $options = array())
{
foreach ($requests as $key => $request) {
$requests[$key] = $this->merge_request($request, false);
}
$options = array_merge($this->options, $options);
// Disallow forcing the type, as that's a per request setting
unset($options['type']);
return Requests::request_multiple($requests, $options);
}
示例6: array
<?php
// First, include Requests
include '../library/Requests.php';
// Next, make sure Requests can load internal classes
Requests::register_autoloader();
// Setup what we want to request
$requests = array(array('url' => 'http://httpbin.org/get', 'headers' => array('Accept' => 'application/javascript')), 'post' => array('url' => 'http://httpbin.org/post', 'data' => array('mydata' => 'something')), 'delayed' => array('url' => 'http://httpbin.org/delay/10', 'options' => array('timeout' => 20)));
// Setup a callback
function my_callback(&$request, $id)
{
var_dump($id, $request);
}
// Tell Requests to use the callback
$options = array('complete' => 'my_callback');
// Send the request!
$responses = Requests::request_multiple($requests, $options);
// Note: the response from the above call will be an associative array matching
// $requests with the response data, however we've already handled it in
// my_callback() anyway!
//
// If you don't believe me, uncomment this:
# var_dump($responses);