本文整理汇总了PHP中curl::hasError方法的典型用法代码示例。如果您正苦于以下问题:PHP curl::hasError方法的具体用法?PHP curl::hasError怎么用?PHP curl::hasError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类curl
的用法示例。
在下文中一共展示了curl::hasError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: makeRequest
/**
* internal function that I use to make all the requests to flickr
*
* @param string $method The Flickr Method that is being requested
* @param array $params An array of the various required and optional fields needed to make the mthod request
*
* @return array The xml turned into an array
* @access public
*/
function makeRequest($method, $params)
{
$this->_clearErrors();
$useCURL = in_array('curl', get_loaded_extensions());
$params['method'] = $method;
$params['api_key'] = $this->_api_key;
$args = array();
foreach ($params as $k => $v) {
array_push($args, urlencode($k) . '=' . urlencode($v));
}
$query_str = implode('&', $args);
$request = $this->_flickr_api_url . '?' . $query_str;
// full url to request
$hit_flickr = true;
// whether or not to make a request to flickr
$request_hash = md5($request);
if ($this->_cache_enabled) {
if ($this->_cache_type == 'db') {
$now = time();
$rows = $this->_cache->findMany("WHERE request = '" . $request_hash . "' AND date_expire > {$now}");
// if any rows found, then use cached response
if (count($rows) > 0) {
$xml = $rows[0]->response;
$hit_flickr = $xml == '' ? true : false;
}
} else {
$now = time();
$file = $this->_cache_dir . md5($request) . '.cache';
if (file_exists($file)) {
$xml = file_get_contents($file);
$hit_flickr = $xml == '' ? true : false;
}
}
}
// only hit flickr if cached request not found above
if ($hit_flickr) {
// whether or not to use curl for request
if ($useCURL) {
$c = new curl($request);
$c->setopt(CURLOPT_FOLLOWLOCATION, true);
$xml = $c->exec();
$error = $c->hasError();
if ($error) {
$this->_error_msg = $error;
return false;
}
$c->close();
} else {
// curl not available so use fsockopen
$url_parsed = parse_url($request);
$host = $url_parsed["host"];
$port = $url_parsed['port'] == 0 ? 80 : $url_parsed['port'];
$path = $url_parsed["path"] . ($url_parsed['query'] != '' ? $path .= "?{$url_parsed[query]}" : '');
$headers = "GET {$path} HTTP/1.0\r\n";
$headers .= "Host: {$host}\r\n\r\n";
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) {
$this->_error_msg = $errstr;
$this->_error_code = $errno;
return false;
} else {
fwrite($fp, $headers);
while (!feof($fp)) {
$xml .= fgets($fp, 1024);
}
fclose($fp);
/*
this seems stupid, but it removes the
headers from the response; if you know
a better way let me know
*/
$xml_start = strpos($xml, '<?xml');
$xml = substr($xml, $xml_start, strlen($xml));
}
}
if ($this->_cache_enabled) {
// store the cached request
if ($this->_cache_type == 'db') {
$this->_cache->request = $request_hash;
$this->_cache->response = $xml;
$this->_cache->date_expire = strtotime("+ {$this->_cache_expire} seconds", time());
$this->_cache->save();
} else {
$file = $this->_cache_dir . $request_hash . '.cache';
$fp = fopen($file, "w");
$result = fwrite($fp, $xml);
fclose($fp);
}
}
}
if ($this->_debug) {
//.........这里部分代码省略.........
示例2: array
//called dummy_log
$darray = array('file_size' => $curl->file_size, 'file_name' => $file_name . '.' . $ext, 'time_started' => time(), 'byte_size' => 0);
$do = fopen($dummy_file, 'w+');
fwrite($do, json_encode($darray));
fclose($do);
}
//Opening video file
$temp_fo = fopen($svfile, 'w+');
$curl->setopt(CURLOPT_FILE, $temp_fo);
// Set up the callback
if (phpversion() >= '5.3.0') {
$curl->setopt(CURLOPT_NOPROGRESS, false);
$curl->setopt(CURLOPT_PROGRESSFUNCTION, 'callback');
}
$curl->exec();
if ($theError = $curl->hasError()) {
$array['error'] = $theError;
echo json_encode($array);
}
//Finish Writing File
fclose($temp_fo);
sleep(10);
$details = file_get_contents($log_file);
$details = json_decode($details, true);
$Upload->add_conversion_queue($details['file_name']);
if (file_exists($log_file)) {
unlink($log_file);
}
if (file_exists($dummy_file)) {
unlink($dummy_file);
}
示例3: curl_post
private function curl_post($URL = NULL, $POST_DATA = NULL)
{
if ($URL == NULL || $POST_DATA == NULL) {
trigger_error("curl_post() ERROR: URL or POST_DATA has not been setted.", E_USER_ERROR);
}
$URL = new curl($URL);
$URL->setopt(CURLOPT_FOLLOWLOCATION, TRUE);
$URL->setopt(CURLOPT_SSL_VERIFYPEER, FALSE);
$URL->setopt(CURLOPT_SSL_VERIFYHOST, FALSE);
$URL->setopt(CURLOPT_POST, TRUE);
$URL->setopt(CURLOPT_POSTFIELDS, $POST_DATA);
$URL->setopt(CURLOPT_USERAGENT, "User-Agent: IIC2.0/PC 2.3.0230");
$curl_result = $URL->exec();
if ($theError = $URL->hasError()) {
echo $theError;
}
$URL->close();
return $curl_result;
}
示例4: curl
<?php
include_once "class.curl.php";
//
// Create a new instance of the curl class and point it
// at the page to be fetched.
//
$c = new curl("http://www.csworks.com/resume/cv.shtml");
//
// By default, curl doesn't follow redirections and this
// page may or may not be available via redirection.
//
$c->setopt(CURLOPT_FOLLOWLOCATION, true);
//
// By default, the curl class expects to return data to
// the caller.
//
echo $c->exec();
//
// Check to see if there was an error and, if so, print
// the associated error message.
//
if ($theError = $c->hasError()) {
echo $theError;
}
//
// Done with the cURL, so get rid of the cURL related resources.
//
$c->close();