本文整理汇总了PHP中Curl::execute方法的典型用法代码示例。如果您正苦于以下问题:PHP Curl::execute方法的具体用法?PHP Curl::execute怎么用?PHP Curl::execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Curl
的用法示例。
在下文中一共展示了Curl::execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
public function get($uriParams = [])
{
if (is_array($uriParams)) {
$uriParams = '?' . http_build_query($uriParams);
} elseif (!is_string($uriParams)) {
throw new Exception('Unsupported variable type');
}
$this->curl->setUrl($this->curl->getUrl() . $uriParams);
return $this->curl->execute();
}
示例2: execute
public function execute()
{
$result = parent::execute();
if ($result === FALSE) {
return FALSE;
} else {
$header = substr($result, 0, $this->info['header_size']);
$body = substr($result, $this->info['header_size']);
$header = explode("\n", $header);
$headers = array();
foreach ($header as $h) {
$h = trim($h);
if (empty($h)) {
continue;
}
$hd = explode(':', $h);
if (count($hd) > 1) {
$headers[trim($hd[0])] = trim($hd[1]);
} else {
$headers[trim($hd[0])] = trim($hd[0]);
}
}
$this->response_headers = $headers;
$this->response_body = $body;
if ($this->info['http_code'] == 200) {
return $this->response_body;
} else {
return FALSE;
}
}
}
示例3: initialize
function initialize()
{
if (!$this->fetched) {
$config =& get_config();
$assetUrl = $config['asset_service'] . $this->node['AssetID'];
$curl = new Curl();
$curl->create($assetUrl);
$curl->option(CURLOPT_HEADER, true);
$curl->option(CURLOPT_NOBODY, true);
$response = $curl->execute();
if ($response) {
$headers = http_parse_headers($response);
$this->size = $headers['Content-Length'];
$this->contentType = $headers['Content-Type'];
if (isset($headers['ETag'])) {
$this->etag = $headers['ETag'];
} else {
if (isset($headers['Etag'])) {
$this->etag = $headers['Etag'];
} else {
$this->etag = '';
}
}
} else {
log_message('error', "InventoryFile: Failed to fetch headers from {$assetUrl}");
}
$this->fetched = true;
}
}
示例4: execute
public function execute()
{
$curl_options = array(CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_URL => $this->generate_url());
$curl = new Curl($curl_options);
$res = $curl->execute();
return json_decode($res);
}
示例5: execute
/**
* @throws PrimePesaException
* @throws \Exception
*/
public function execute()
{
$params = array();
$params['cmd'] = 'balance';
$params['secret_key'] = $this->getSecretKey();
$result = Curl::execute($params);
$this->_assertNotError($result);
$this->result = $result;
}
示例6: isAuthentic
/**
* @return bool
* @throws PrimePesaException
* @throws \Exception
*/
public function isAuthentic()
{
$params = array();
$params['cmd'] = 'verify';
$params['secret_key'] = $this->getSecretKey();
$params = array_merge($params, $this->data);
$results = Curl::execute($params);
$this->_assertNotError($results);
return $results['status'] == 'VERIFIED';
}
示例7: get
function get($url, $userAgent = '', $httpHeaders = '', $username = '', $password = '')
{
$ret = Curl::execute('GET', $url, '', $userAgent, $httpHeaders, $username, $password);
if (false === $ret) {
return false;
}
if (is_array($ret)) {
return false;
}
return $ret;
}
示例8: url_exists
/**
* url_exists function.
* Checks to see if an url exists
*
* @access public
* @param string $url
* @return bool
*/
public static function url_exists($url)
{
$curl_options = array(CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_URL => $url);
$curl = new Curl($curl_options);
try {
$curl->execute();
$error = FALSE;
} catch (Exception $e) {
$error = TRUE;
}
return $error;
}
示例9: create_asset
function create_asset($assetID, $creatorID, $contentType, $filename)
{
$CI =& get_instance();
$CI->load->library('Curl');
$CI->load->helper('path');
$filename = rtrim(set_realpath($filename), '/');
$params = array('AssetID' => $assetID, 'CreatorID' => $creatorID, 'Asset' => "@{$filename};type={$contentType}");
echo 'Posting ' . $filename . ' to ' . $CI->config->item('asset_service') . '<br/>';
$curl = new Curl();
$curl->create($CI->config->item('asset_service'));
$curl->option(CURLOPT_POST, TRUE);
$curl->option(CURLOPT_POSTFIELDS, $params);
$curl->http_method('post');
$response = json_decode($curl->execute(), TRUE);
if (!isset($response)) {
$response = array('Message' => 'Invalid or missing response. ' . $curl->error_string);
}
return $response;
}
示例10: ping
public static function ping()
{
$url = "http://" . $_SERVER['HTTP_HOST'] . '/admin/ping/technorati';
$options = array(CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_URL => $url);
$curl = new Curl($options);
$curl->execute();
}
示例11: _zest_news
public function _zest_news()
{
return "";
$html = "<h2>Zest News</h2><hr/>";
$url = "http://zestcms.com/rss/4";
$curl_options = array(CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_URL => $url);
$curl = new Curl($curl_options);
$data = new SimpleXMLElement($curl->execute());
$data = $data->channel->item;
$arr = array();
$i = 0;
foreach ($data as $item) {
if ($i == 5) {
break;
}
$arr[] = $item;
$i++;
}
$arr = array_reverse($arr);
foreach ($arr as $item) {
$html .= "<p>" . date('d M', strtotime($item->pubDate)) . "<br/><a href='" . $item->link . "' target='_BLANK'>" . $item->title . "</a></p><hr/>";
}
return $html;
}
示例12: requestCache
/**
* @param string $url
* @param Curl $curl
* @param callable $callback
* @param int $maxAge
* @param bool $refreshInBackground
* @return mixed
*/
public static function requestCache($url, Curl $curl = null, $callback = null, $maxAge = self::DEFAULT_CACHE_MAX_AGE, $refreshInBackground = true)
{
$return = false;
$returnValue = null;
if (!$curl) {
$curl = new Curl();
$return = true;
$callback = function ($content) use(&$returnValue) {
$returnValue = $content;
};
}
$stmt = self::getStatement('SELECT * FROM request_cache WHERE url = ?');
$stmt->execute(array($url));
$stmt->bindColumn('timestamp', $timestamp);
$stmt->bindColumn('etag', $etag);
$stmt->bindColumn('content', $content);
$stmt->bindColumn('refresh', $refresh);
$stmt->fetch(PDO::FETCH_BOUND);
$shouldRefresh = $timestamp < time() - 60 * $maxAge;
$refreshInBackground = $refreshInBackground && !is_null($content);
if ($shouldRefresh && $refreshInBackground && $refresh < time() - 60) {
self::getStatement('UPDATE request_cache SET refresh = ? WHERE url = ?')->execute(array(time(), $url));
self::$refreshUrls[] = $url;
}
if (!$shouldRefresh || $refreshInBackground) {
$content = json_decode($content);
$stmt = self::getStatement('SELECT url, content FROM request_cache WHERE parent = ? ORDER BY `timestamp` DESC');
while ($stmt->execute(array($url)) && ($data = $stmt->fetchObject())) {
$content = array_merge($content, json_decode($data->content));
$url = $data->url;
}
if (is_callable($callback)) {
$callback($content);
}
return $returnValue;
}
$responses = array();
$handleResponse = function (CurlResponse $response, $content, $parent = null) use(&$handleResponse, $curl, &$responses, $stmt, $callback) {
$url = $response->request->url;
if ($response && in_array($response->status, array(200, 304))) {
$checkNext = false;
if (304 == $response->status) {
$response->content = $content;
$checkNext = true;
} elseif (false === stripos($response->contentType, 'json')) {
$response->content = json_encode($response->content);
}
$responses[] = $response->content;
Workflow::getStatement('REPLACE INTO request_cache VALUES(?, ?, ?, ?, 0, ?)')->execute(array($url, time(), $response->etag, $response->content, $parent));
if ($checkNext || $response->link && preg_match('/<(.+)>; rel="next"/U', $response->link, $match)) {
$stmt = Workflow::getStatement('SELECT * FROM request_cache WHERE parent = ?');
$stmt->execute(array($url));
if ($checkNext) {
$stmt->bindColumn('url', $nextUrl);
} else {
$nextUrl = $match[1];
}
$stmt->bindColumn('etag', $etag);
$stmt->bindColumn('content', $content);
$stmt->fetch(PDO::FETCH_BOUND);
if ($nextUrl) {
$curl->add(new CurlRequest($nextUrl, $etag, function (CurlResponse $response) use($handleResponse, $url, $content) {
$handleResponse($response, $content, $url);
}));
return;
}
} else {
Workflow::getStatement('DELETE FROM request_cache WHERE parent = ?')->execute(array($url));
}
} else {
Workflow::getStatement('DELETE FROM request_cache WHERE url = ?')->execute(array($url));
$url = null;
}
if (is_callable($callback)) {
if (empty($responses)) {
$callback(array());
return;
}
if (1 === count($responses)) {
$callback(json_decode($responses[0]));
return;
}
$callback(array_reduce($responses, function ($content, $response) {
return array_merge($content, json_decode($response));
}, array()));
}
};
$curl->add(new CurlRequest($url, $etag, function (CurlResponse $response) use(&$responses, $handleResponse, $callback, $content) {
$handleResponse($response, $content);
}));
if ($return) {
$curl->execute();
//.........这里部分代码省略.........
示例13: connect
/**
* cURL connection function. Returns data from Twitter and interfaces with
* debug function.
*
* @param bool $login Login to Twitter?
* @param bool $post Use POST instead of GET?
* @param array $post_data Array data for POST.
* @return string
*/
private function connect($login = FALSE, $post = FALSE, $post_data = NULL)
{
// If credentials are required add them
if ($login) {
$login = $this->login;
}
// add default header info
$this->headers[] = 'Expect:';
$curl_options = array(CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_URL => $this->url);
// curl init
$curl = new Curl($curl_options);
// add curl options
if (count($this->headers) > 0) {
$curl->addOption(CURLOPT_HTTPHEADER, $this->headers);
}
if ($login) {
$curl->addOption(CURLOPT_USERPWD, $this->login);
}
if ($post) {
$curl->addOption(CURLOPT_POST, TRUE);
}
if (is_array($post_data)) {
$curl->addOption(CURLOPT_POSTFIELDS, $post_data);
}
// retrieve data
$data = $curl->execute($this->ignore_curl_error_numbers);
// set curl http status
$this->status = $curl->status();
// set last call
$this->last = $this->url;
// clear settings
$this->url = '';
$this->headers = '';
// debug output
// if (!IN_PRODUCTION AND Kohana::config('twitter.debug')) $this->debugo($data, $post_data);
return $data;
}
示例14: check_for_feed
/**
* check_for_feed function.
*
* @access public
* @param string $url
* @return boolean
*/
public function check_for_feed($url)
{
$query = "select title,href from html where url='" . $url . "' and xpath='//link' and type='application/rss+xml'";
$q = urlencode($query);
$url = 'http://query.yahooapis.com/v1/public/yql?q=' . $q . '&format=json';
$curl_options = array(CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_URL => $url);
$curl = new Curl($curl_options);
$data = $curl->execute();
$data = json_decode($data);
if (!isset($data->error) && isset($data->query->results)) {
if (is_array($data->query->results->link)) {
foreach ($data->query->results->link as $link) {
if (isset($link->href) && strstr($link->href, 'http://') != FALSE) {
$this->feeds[$link->title] = array("profile" => $url, "feed" => str_replace('&lang', '&lang', $link->href));
}
}
} else {
if (isset($data->query->results->link->href) && strstr($data->query->results->link->href, 'http://') != FALSE) {
$this->feeds[$data->query->results->link->title] = array("profile" => $url, "feed" => str_replace('&lang', '&lang', $data->query->results->link->href));
}
}
return TRUE;
} else {
return FALSE;
}
}
示例15: mulitGet
public function mulitGet($urls)
{
$curl = new Curl();
$curl->setUrls($urls);
return $curl->execute();
}