本文整理汇总了PHP中curl::exec方法的典型用法代码示例。如果您正苦于以下问题:PHP curl::exec方法的具体用法?PHP curl::exec怎么用?PHP curl::exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类curl
的用法示例。
在下文中一共展示了curl::exec方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUrl
function getUrl($url, $requestType = 'GET', $timeout = 30)
{
$curl = new curl();
$curl->curl($url);
if ($requestType == "POST") {
$postString = "";
foreach ($postArray as $postField => $postValue) {
$postString .= "{$postField}=" . $postValue . "&";
}
$postString .= "Enter=";
$curl->setopt(CURLOPT_POST, 1);
$curl->setopt(CURLOPT_POSTFIELDS, $postString);
}
$curl->setopt(CURLOPT_SSL_VERIFYPEER, FALSE);
$curl->setopt(CURLOPT_USERAGENT, MAGPIE_USER_AGENT);
$curl->setopt(CURLOPT_FOLLOWLOCATION, 1);
// allow redirects
$curl->setopt(CURLOPT_RETURNTRANSFER, 1);
// return into a variable
$curl->setopt(CURLOPT_TIMEOUT, $timeout);
// times out after x seconds
$result = $curl->exec();
// run the whole process
$curl->close();
return $result;
}
示例2: readFeed
function readFeed($url, $type = '')
{
$this->url = $url;
$this->type = $type;
$urltocapture = new curl($this->url);
$urltocapture->setopt(CURLOPT_HTTPGET, true);
$this->fileRead = $urltocapture->exec();
if (empty($this->fileRead) or !$this->fileRead) {
return 101;
}
$ext = new btext();
$this->feedArray = $ext->xml2array($this->fileRead);
switch ($this->type) {
case 'youtube':
return $this->youtube();
break;
case 'vimeo':
return $this->vimeo();
break;
case 'dailymotion':
return $this->dailymotion();
break;
default:
return false;
break;
}
}
示例3: request
function request($url)
{
$hash = md5($url);
$cache = SCHED_API_DIR . '/cache/' . $hash;
// TODO check if cache is expired; make expired admin option
if (file_exists($cache)) {
$out = file_get_contents($cache);
} else {
$c = new curl($url);
$out = $c->exec();
$c->close();
file_put_contents($cache, $out);
}
return $out;
}
示例4: 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) {
//.........这里部分代码省略.........
示例5: 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;
}
示例6: array
//Here we will get file size and write it in a file
//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);
示例7: capture
function capture()
{
$obj = new stdClass();
$arry = $this->readFeed($this->feed['url'], $this->feed['type']);
$obj->title = $arry['title'];
$obj->description = $arry['description'];
$obj->videoThumbnail = $arry['videoThumbnail'];
$obj->videoTags = $arry['videoTags'];
$obj->videoSrc = $arry['videoSrc'];
if (empty($obj->title) or empty($obj->videoSrc) or empty($obj->videoThumbnail)) {
if (!empty($arry['error'])) {
return $arry['error'];
} else {
return $arry;
}
}
$obj->fileName = time() . $this->video_id . ".jpg";
$urltocapture = new curl($obj->videoThumbnail);
$urltocapture->setopt(CURLOPT_HTTPGET, true);
$obj->fileContent = $urltocapture->exec();
$obj->type = $this->feed['type'];
return $obj;
}
示例8: 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();