本文整理汇总了PHP中EpiCurl::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP EpiCurl::getInstance方法的具体用法?PHP EpiCurl::getInstance怎么用?PHP EpiCurl::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EpiCurl
的用法示例。
在下文中一共展示了EpiCurl::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($url, $depth = 3, $limitUrls = 59)
{
$this->_url = $url;
$this->_depth = $depth;
$parsed = parse_url($url);
$this->_host = $parsed['host'];
$this->_curl = \EpiCurl::getInstance();
$this->_limitUrls = $limitUrls;
$this->_pool = new \Pool(10);
}
示例2: __call
public function __call($name, $params = null)
{
$parts = explode('_', $name);
$method = strtoupper(array_shift($parts));
$parts = implode('_', $parts);
$path = '/' . preg_replace('/[A-Z]|[0-9]+/e', "'/'.strtolower('\\0')", $parts) . '.json';
$args = !empty($params) ? array_shift($params) : null;
// intercept calls to the search api
if (preg_match('/^(search|trends)/', $parts)) {
$query = isset($args) ? http_build_query($args) : '';
$url = "{$this->searchUrl}{$path}?{$query}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
return new EpiTwitterJson(EpiCurl::getInstance()->addCurl($ch));
}
$url = $this->getUrl("{$this->apiUrl}{$path}");
return new EpiTwitterJson(call_user_func(array($this, 'httpRequest'), $method, $url, $args));
}
示例3: getVideoData
/**
* Get video data from Youtube API.
*
* @param string $video_url Video URL or video ID.
* @return array
*/
public function getVideoData($video_url)
{
$video_id = $this->_getVideoId($video_url);
$multi_curl = EpiCurl::getInstance();
$curl = curl_init($this->api_url . $video_id);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = $multi_curl->addCurl($curl);
if (200 !== $response->code) {
return false;
}
try {
$xml_data = @new SimpleXMLElement($response->data);
} catch (\Exception $e) {
if ('Invalid id' === $response->data) {
return false;
}
}
$video_data['video_id'] = $video_id;
$video_data['url_player'] = (string) $xml_data->link[0]->attributes()->href[0];
$media_group = $xml_data->children($this->media_namespace);
$video_data['title'] = (string) $media_group->group->title;
$video_data['description'] = (string) $media_group->group->description;
$video_data['keywords'] = explode(',', (string) $media_group->group->keywords);
if (!isset($media_group->group->content[0])) {
return false;
}
$content_attrs = $media_group->group->content[0]->attributes();
$video_data['url_embed'] = (string) $content_attrs['url'];
$video_data['duration'] = (int) $content_attrs['duration'];
foreach ($media_group->group->thumbnail as $key => $val) {
$thumb_attrs = $val->attributes();
$thumb_width = (int) $thumb_attrs['width'];
if ($thumb_width == 120) {
$video_data['thumbnails'][] = (string) $thumb_attrs['url'];
}
}
return $video_data;
}
示例4: request
private function request($method, $endpoint, $params = null, $username = null, $password = null)
{
if (preg_match('#^https?://#', $endpoint)) {
$url = $endpoint;
} else {
$url = $this->getApiUrl($endpoint);
}
if ($this->accessToken) {
$params['oauth_token'] = $this->accessToken;
}
if ($method === 'GET') {
$url .= is_null($params) ? '' : '?' . http_build_query($params, '', '&');
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->requestTimeout);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
if ($method === 'POST' && $params !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
}
$resp = new EpiFoursquareJson(EpiCurl::getInstance()->addCurl($ch), $this->debug);
if (!$this->isAsynchronous) {
$resp->responseText;
}
return $resp;
}
示例5: nonblock_post
function nonblock_post($url, $data)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_COOKIEFILE, $this->cookie_file);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$mc = EpiCurl::getInstance();
$curl1 = $mc->addCurl($curl);
}
示例6: __construct
public function __construct($consumerKey = "BBE15ugu1VLyJUxhxlgYQ", $consumerSecret = "2KVw2TRS9xXhGapSeR3RaUpuM2SY6kpiUUYEHWgQ", $signatureMethod = 'HMAC-SHA1')
{
$this->consumerKey = $consumerKey;
$this->consumerSecret = $consumerSecret;
$this->signatureMethod = $signatureMethod;
$this->curl = EpiCurl::getInstance();
}
示例7: _updateFeeds
/**
* Loads all the feeds from the cache or new from the server
*
* @version 1.0.0
* @since Version 1.0.0
* @access private
* @return array An array of RSS feed XML
**/
public function _updateFeeds()
{
$EE =& get_instance();
libxml_use_internal_errors(true);
require_once PATH_THIRD . NSM_ADDON_UPDATER_ADDON_ID . "/libraries/Epicurl.php";
$sources = false;
$feeds = false;
$mc = EpiCurl::getInstance();
foreach ($EE->addons->_packages as $addon_id => $addon) {
$config_file = PATH_THIRD . '/' . $addon_id . '/config.php';
if (!file_exists($config_file)) {
continue;
}
include $config_file;
$data = false;
# Is there a file with the xml url?
if (isset($config['nsm_addon_updater']['versions_xml'])) {
$url = $config['nsm_addon_updater']['versions_xml'];
# Get the XML again if it isn't in the cache
if ($this->test_mode || !($response = $this->_readCache(md5($url)))) {
log_message('debug', "Checking for updates via CURL: {$addon_id}");
$c = false;
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
@curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
$curls[$addon_id] = $mc->addCurl($c);
$response = $curls[$addon_id]->data;
$this->_createCacheFile($response, md5($url));
// if theres an error with the curl request set an error
if (!in_array($curls[$addon_id]->code, array(200, 301, 302))) {
$data = array('error' => 'Could not find changelog for add-on', 'row_class' => 'error');
}
}
if (!isset($data['error'])) {
# If there isn't an error with the XML
try {
$xml = @simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA);
$data = $xml;
} catch (Exception $e) {
// problem with data
$data = false;
}
}
// data still false? mark as an error
if (!$data) {
$data = array('error' => "There was a problem processing the <a href='{$config['nsm_addon_updater']['versions_xml']}' target='_blank'>versions.xml</a> file for this add-on", 'row_class' => 'error');
}
} else {
if (!$this->hide_incompatible) {
$data = array('error' => 'Addon doesn\'t have a NSM Addon Updater URL', 'row_class' => '');
}
}
if ($data) {
$feeds[$addon_id] = $data;
}
unset($config);
}
return $feeds;
}
示例8: _out
/**
* Performs heavy lifting of plugin, processing output and returning final tags
* [Adapted from CodeIgniter Carabiner library]
*
* @return string The final tag to be returned to template
*/
private function _out()
{
// our return variable
$out = '';
// if we are not combining, then minify each file in turn
if ($this->combine == 'no') :
$tags = array();
foreach ($this->filesdata as $key => $file) :
$this->filesdata[$key]['cache_filename'] = $file['lastmodified'] . md5($file['name']) . '.' . $this->type;
if (file_exists($this->EE->functions->remove_double_slashes($this->cache_path . '/' . $this->filesdata[$key]['cache_filename'])))
{
log_message('debug', 'Minimee is returning a cached file: ' . $this->EE->functions->remove_double_slashes($this->cache_path . '/' . $this->filesdata[$key]['cache_filename']));
$tags[$key] = $this->_tag($this->filesdata[$key]['cache_filename']);
}
else
{
// must get contents of file to minify
switch ($file['type']) :
case ('stylesheet');
case ('remote') :
switch ($this->remote_mode)
{
case ('fgc') :
// I hate to suppress errors, but it's only way to avoid one from a 404 response
$response = @file_get_contents($file['name']);
if ($response && isset($http_response_header) && (substr($http_response_header[0], 9, 3) < 400))
{
$this->_cache($this->filesdata[$key]['cache_filename'], $this->_minify($response));
$tags[$key] = $this->_tag($this->filesdata[$key]['cache_filename']);
}
else
{
throw new Exception('A problem occurred while fetching the following over file_get_contents(): ' . $file['name']);
}
break;
case ('curl') :
if ( ! isset($epicurl))
{
require_once(PATH_THIRD . 'minimee/libraries/EpiCurl.php');
$epicurl = EpiCurl::getInstance();
}
$ch = FALSE;
$ch = curl_init($file['name']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$curls[$key] = $epicurl->addCurl($ch);
if ($curls[$key]->code >= 400)
{
throw new Exception('Error encountered while fetching \'' . $this->filesdata[$key]['name'] . '\' over cURL.');
}
$this->_cache($this->filesdata[$key]['cache_filename'], $this->_minify($curls[$key]->data));
$tags[$key] = $this->_tag($this->filesdata[$key]['cache_filename']);
break;
default :
throw new Exception('Could not fetch file \'' . $file['name'] . '\' because neither cURL or file_get_contents() appears available.');
break;
}
break;
case ('local') :
default :
$rel = dirname($this->EE->functions->remove_double_slashes($this->base_url . '/' . $file['name'] . '/'));
$contents = file_get_contents(realpath($this->EE->functions->remove_double_slashes($this->base_path . '/' . $file['name']))) . "\n";
$this->_cache($this->filesdata[$key]['cache_filename'], $this->_minify($contents, $rel));
$tags[$key] = $this->_tag($this->filesdata[$key]['cache_filename']);
break;
endswitch;
}
endforeach;
$out = implode('', $tags);
// combine (& possibly minify) files
else :
$lastmodified = 0;
$cache_name = '';
//.........这里部分代码省略.........
示例9: fetch
/**
* Fetches the given URL for every added account or a single URL if credentials aren't required.
*
* @param string $url Url to fetch.
* @param boolean $require_credentials Whether user needs to be authenticated or not.
* @param boolean $http_post Send data as a POST.
* @return array
*/
public function fetch()
{
$mc = EpiCurl::getInstance();
foreach (self::$accounts as $account_name => $values) {
foreach ($values['methods'] as $method_name => $method) {
$curl_handle = curl_init($method['url']);
// Due to headers' lios: http://www.shoemoney.com/2008/12/29/lib-curl-twitter-api-expect-100-continue-pain-and-how-to-fix-it/
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
// x seconds for timeout
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 5);
if ($method['require_credentials']) {
curl_setopt($curl_handle, CURLOPT_USERPWD, $values['credentials']);
}
if ($method['http_post']) {
curl_setopt($curl_handle, CURLOPT_POST, true);
}
self::$accounts[$account_name][$method_name]['curl'] = $mc->addCurl($curl_handle);
}
}
foreach (self::$accounts as $account_name => $values) {
foreach ($values['methods'] as $method_name => $value) {
self::$accounts[$account_name][$method_name] = self::$accounts[$account_name][$method_name]['curl']->data;
// ->code can be returned as well.
}
// Finished with all this account methods, unset:
unset(self::$accounts[$account_name]['methods']);
unset(self::$accounts[$account_name]['credentials']);
unset(self::$accounts[$account_name]['curl']);
}
if (empty(self::$accounts[self::NO_ACCOUNT_NAME])) {
unset(self::$accounts[self::NO_ACCOUNT_NAME]);
}
return self::$accounts;
}
示例10: get_update_feeds
private function get_update_feeds()
{
require APPPATH . "third_party/nsm_addon_updater/libraries/Epicurl.php";
$sources = FALSE;
$feeds = FALSE;
$mc = EpiCurl::getInstance();
foreach ($this->EE->extensions->OBJ as $addon_id => $addon) {
if (isset($addon->versions_xml)) {
if (!($xml = $this->get_cache($addon->versions_xml))) {
$c = FALSE;
$c = curl_init($addon->versions_xml);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
$curls[$addon_id] = $mc->addCurl($c);
$xml = FALSE;
if ($curls[$addon_id]->code == "200" || $curls[$addon_id]->code == "302") {
$xml = $curls[$addon_id]->data;
$this->write_cache($xml, $addon->versions_xml);
}
}
if ($xml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)) {
$feeds[$addon_id] = $xml;
}
}
}
return $feeds;
}
示例11: array
"Name":"Feast of Veggie Pizzas",
"Rating":125,
"Type":8,
"Count":1,
"CreatedItemId":12602,
"RequiresRecipeItem":true,
"Ingredients":[{"ItemID":12346,"Count":10}]}
}
}
*/
//Quick and dirty discipline name to ID translation.
$disciplines = array('Huntsman' => 1, 'Artificer' => 2, 'Weaponsmith' => 3, 'Armorsmith' => 4, 'Leatherworker' => 5, 'Tailor' => 6, 'Jeweler' => 7, 'Chef' => 8);
//Gather all recipes by recipe_id
$curl = CurlRequest::newInstance(getAppConfig('gw2spidy.gw2api_url') . "/v1/recipes.json")->exec();
$data = json_decode($curl->getResponseBody(), true);
$multi_curl = EpiCurl::getInstance();
$recipe_curls = array();
$recipe_count = count($data['recipes']);
$error_values = array();
$i = 0;
$ii = 0;
foreach (array_chunk($data['recipes'], 1000) as $recipes) {
//Add all curl requests to the EpiCurl instance.
foreach ($recipes as $recipe_id) {
$i++;
$ch = curl_init(getAppConfig('gw2spidy.gw2api_url') . "/v1/recipe_details.json?recipe_id={$recipe_id}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$recipe_curls[$recipe_id] = $multi_curl->addCurl($ch);
echo "[{$i} / {$recipe_count}]: {$recipe_id}\n";
}
foreach ($recipes as $recipe_id) {
示例12: run
public function run()
{
$curl = EpiCurl::getInstance();
$newUrl = $this->checkHeaders($this->url);
$this->response = file_get_contents($this->url);
//$curl->addURL($newUrl);
// var_dump($this->response);die();
}
示例13: __construct
public function __construct($access, $secret)
{
$this->accessID = $access;
$this->secretKey = $secret;
$this->curl = EpiCurl::getInstance();
}
示例14:
static function &getInstance($fbId = null)
{
static $inst = null;
$class = __CLASS__;
if ($inst === null) {
$inst = new $class();
$inst->apikey = '03f99def50e358c05b3855039c85d097';
$inst->secret = '9cd9d117a7d2112e80448eb15c41fd11';
$inst->fbId = '500273081';
//$fbId;
$inst->version = '1.0';
$inst->curl = EpiCurl::getInstance();
}
return $inst;
}
示例15: __construct
function __construct($key)
{
$this->key = $key;
$this->epiCurl = EpiCurl::getInstance();
}