本文整理汇总了PHP中curl_getinfo函数的典型用法代码示例。如果您正苦于以下问题:PHP curl_getinfo函数的具体用法?PHP curl_getinfo怎么用?PHP curl_getinfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curl_getinfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: makeRequest
/**
* 执行一个 HTTP 请求
*
* @param string $url 执行请求的URL
* @param mixed $params 表单参数
* 可以是array, 也可以是经过url编码之后的string
* @param mixed $cookie cookie参数
* 可以是array, 也可以是经过拼接的string
* @param string $method 请求方法 post / get
* @param string $protocol http协议类型 http / https
* @return array 结果数组
*/
public static function makeRequest($url, $params, $cookie, $method = 'post', $protocol = 'http')
{
$query_string = self::makeQueryString1($params);
$cookie_string = self::makeCookieString($cookie);
$ch = curl_init();
if ('get' == $method) {
curl_setopt($ch, CURLOPT_URL, "{$url}?{$query_string}");
} else {
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
}
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
// disable 100-continue
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
if (!empty($cookie_string)) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie_string);
}
if ('https' == $protocol) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
$ret = curl_exec($ch);
$err = curl_error($ch);
if (false === $ret || !empty($err)) {
$errno = curl_errno($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return array('result' => false, 'errno' => $errno, 'msg' => $err, 'info' => $info);
}
curl_close($ch);
return array('result' => true, 'msg' => $ret);
}
示例2: curlConnection
private function curlConnection($method = 'GET', $url, array $data = null, $timeout, $charset)
{
if (strtoupper($method) === 'POST') {
$postFields = $data ? http_build_query($data, '', '&') : "";
$contentLength = "Content-length: " . strlen($postFields);
$methodOptions = array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postFields);
} else {
$contentLength = null;
$methodOptions = array(CURLOPT_HTTPGET => true);
}
$options = array(CURLOPT_HTTPHEADER => array("Content-Type: application/x-www-form-urlencoded; charset=" . $charset, $contentLength), CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CONNECTTIMEOUT => $timeout);
$options = $options + $methodOptions;
$curl = curl_init();
curl_setopt_array($curl, $options);
$resp = curl_exec($curl);
$info = curl_getinfo($curl);
$error = curl_errno($curl);
$errorMessage = curl_error($curl);
curl_close($curl);
$this->setStatus((int) $info['http_code']);
$this->setResponse((string) $resp);
if ($error) {
throw new Exception("CURL can't connect: {$errorMessage}");
return false;
} else {
return true;
}
}
示例3: getDom
public function getDom($url, $post = false)
{
$f = fopen(CURL_LOG_FILE, 'a+');
// curl session log file
if ($this->lastUrl) {
$header[] = "Referer: {$this->lastUrl}";
}
$curlOptions = array(CURLOPT_ENCODING => 'gzip,deflate', CURLOPT_AUTOREFERER => 1, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_TIMEOUT => 120, CURLOPT_URL => $url, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 9, CURLOPT_RETURNTRANSFER => 1, CURLOPT_HEADER => 0, CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36", CURLOPT_COOKIEFILE => COOKIE_FILE, CURLOPT_COOKIEJAR => COOKIE_FILE, CURLOPT_STDERR => $f, CURLOPT_VERBOSE => true);
if ($post) {
// add post options
$curlOptions[CURLOPT_POSTFIELDS] = $post;
$curlOptions[CURLOPT_POST] = true;
}
$curl = curl_init();
curl_setopt_array($curl, $curlOptions);
$data = curl_exec($curl);
$this->lastUrl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
// get url we've been redirected to
curl_close($curl);
if ($this->dom) {
$this->dom->clear();
$this->dom = false;
}
$dom = $this->dom = str_get_html($data);
fwrite($f, "{$post}\n\n");
fwrite($f, "-----------------------------------------------------------\n\n");
fclose($f);
return $dom;
}
示例4: send
function send()
{
//check the fields to make sure that they are not NULL
$this->isComplete();
$url = $this->host . $this->postPath;
$postBody = json_encode($this->data);
$sign = md5("POST" . $url . $postBody . $this->appMasterSecret);
$url = $url . "?sign=" . $sign;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postBody);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlErrNo = curl_errno($ch);
$curlErr = curl_error($ch);
curl_close($ch);
//print($result . "\r\n");
if ($httpCode == "0") {
// Time out
throw new Exception("Curl error number:" . $curlErrNo . " , Curl error details:" . $curlErr . "\r\n");
} else {
if ($httpCode != "200") {
// We did send the notifition out and got a non-200 response
throw new Exception("Http code:" . $httpCode . " details:" . $result . "\r\n");
} else {
return $result;
}
}
}
示例5: call
/**
* Make an api request
*
* @param string $resource
* @param array $params
* @param string $method
*/
public function call($resource, $params = array())
{
$queryString = 'access_token=' . $this->getAccessToken();
if (!empty($params) && is_array($params)) {
$queryString .= http_build_query($params);
}
$requestUrl = self::API_URL . $resource . '/?' . $queryString;
$curl = curl_init();
$curl_options = array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $requestUrl, CURLOPT_TIMEOUT => 30, CURLOPT_HTTPHEADER => array('Accept: application/json', 'appid: nike'));
curl_setopt_array($curl, $curl_options);
$response = curl_exec($curl);
$curl_info = curl_getinfo($curl);
//@todo test for curl error
if ($response === FALSE) {
throw new Exception(curl_error($curl), curl_errno($curl));
}
curl_close($curl);
//@todo test for any non 200 response
if ($curl_info['http_code'] != 200) {
throw new Exception("Response: Bad response - HTTP Code:" . $curl_info['http_code']);
}
$jsonArray = json_decode($response);
if (!is_object($jsonArray)) {
throw new Exception("Response: Response was not a valid response");
}
return $jsonArray;
}
示例6: updateIndex
function updateIndex($lang, $file)
{
$fileData = readFileData($file);
$filename = $file->getPathName();
list($filename) = explode('.', $filename);
$path = $filename . '.html';
$id = str_replace($lang . '/', '', $filename);
$id = str_replace('/', '-', $id);
$id = trim($id, '-');
$url = implode('/', array(ES_URL, ES_INDEX, $lang, $id));
$data = array('contents' => $fileData['contents'], 'title' => $fileData['title'], 'url' => $path);
$data = json_encode($data);
$size = strlen($data);
$fh = fopen('php://memory', 'rw');
fwrite($fh, $data);
rewind($fh);
echo "Sending request:\n\tfile: {$file}\n\turl: {$url}\n";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, $fh);
curl_setopt($ch, CURLOPT_INFILESIZE, $size);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$metadata = curl_getinfo($ch);
if ($metadata['http_code'] > 400) {
echo "[ERROR] Failed to complete request.\n";
var_dump($response);
exit(2);
}
curl_close($ch);
fclose($fh);
echo "Sent {$file}\n";
}
示例7: make_call
function make_call($call_options)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $call_options['route']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $call_options['credentials']);
curl_setopt($ch, CURLOPT_USERAGENT, $call_options['userAgent']);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: ' . $call_options['contentType']));
switch ($call_options['method']) {
case CS_REST_PUT:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, CS_REST_PUT);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($call_options['data'])));
curl_setopt($ch, CURLOPT_POSTFIELDS, $call_options['data']);
break;
case CS_REST_POST:
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $call_options['data']);
break;
case CS_REST_DELETE:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, CS_REST_DELETE);
break;
}
$response = curl_exec($ch);
if (!$response && $response !== '') {
trigger_error('Error making request with curl_error: ' . curl_error($ch));
}
$this->_log->log_message('API Call Info for ' . $call_options['method'] . ' ' . curl_getinfo($ch, CURLINFO_EFFECTIVE_URL) . ': ' . curl_getinfo($ch, CURLINFO_SIZE_UPLOAD) . ' bytes uploaded. ' . curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD) . ' bytes downloaded' . ' Total time (seconds): ' . curl_getinfo($ch, CURLINFO_TOTAL_TIME), get_class($this), CS_REST_LOG_VERBOSE);
$result = array('code' => curl_getinfo($ch, CURLINFO_HTTP_CODE), 'response' => $response);
curl_close($ch);
return $result;
}
示例8: toastup
function toastup($channel, $message)
{
$channel_uri = urldecode($channel);
$toast_xml = '<?xml version="1.0" encoding="utf-8" ?>
<wp:Notification xmlns:wp="WPNotification">
<wp:Toast>
<wp:Text1>' . 信息: . '</wp:Text1>
<wp:Text2>' . $message . '</wp:Text2>
</wp:Toast>
</wp:Notification>';
$headers = array('Content-Type: text/xml', "Content-Length: " . strlen($toast_xml), "X-WindowsPhone-Target: toast", "X-NotificationClass: 2");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $channel_uri);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 2);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{$toast_xml}");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$response = curl_getinfo($ch);
curl_close($ch);
return $response['http_code'];
}
示例9: query
public function query($domain, $postvars)
{
$this->log_proxy(' domain: ' . $domain);
$this->log_proxy('POSTVARS: ' . $postvars);
$ch = curl_init($domain);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
// curl_setopt( $ch, CURLOPT_USERAGENT , isset( $_SERVER[ 'User-Agent' ]) ? $_SERVER[ 'User-Agent' ] : '' );
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
// curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_REFERER, $domain);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_AUTOREFERER, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'ses_' . session_id());
curl_setopt($ch, CURLOPT_COOKIEFILE, 'ses_' . session_id());
// curl_setopt( $ch, CURLOPT_COOKIE , $COOKIE );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
$content = curl_exec($ch);
$response = curl_getinfo($ch);
curl_close($ch);
unlink('ses_' . session_id());
return $content;
}
示例10: getResponse
private function getResponse($arPost)
{
if (!function_exists('curl_init')) {
die('curl library not installed');
return false;
}
if ($this->isAuth()) {
$arPost = array_merge($arPost, $this->auth);
}
$data = array();
foreach ($arPost as $k => $v) {
$data[] = urlencode($k) . '=' . urlencode($v);
}
$data[] = 'language=' . $this->language;
$data = implode('&', $data);
$handler = curl_init();
curl_setopt($handler, CURLOPT_URL, $this->url);
curl_setopt($handler, CURLOPT_HEADER, 0);
curl_setopt($handler, CURLOPT_POST, true);
curl_setopt($handler, CURLOPT_POSTFIELDS, $data);
curl_setopt($handler, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($handler, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($handler, CURLOPT_USERAGENT, $this->agent);
curl_setopt($handler, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($handler);
//print_r($content);
$arRequest = curl_getinfo($handler);
//print_r($arRequest);
curl_close($handler);
if (strpos($content, '{') !== false) {
$content = $this->objectToArray(json_decode($content));
}
return $content;
}
示例11: _postCurl
private function _postCurl($url, $params = array())
{
//init cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_USERPWD, $this->user . ':' . $this->pass);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, TRUE);
if (!empty($params)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
}
// run cURL
$data = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$this->data = $data;
$this->status = $status;
// result return 200, 302 for OK, 400, 500 for BAD
if ($status == 200 || $status == 302) {
return true;
} else {
return false;
}
}
示例12: get
/**
* A proxy curl implementation to get the content of the url.
*
* @param string $url
*
* @return string
* @throws CurlException
*/
public function get($url)
{
$ch = curl_init($url);
if (!ini_get('open_basedir')) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
}
if (self::$proxy) {
curl_setopt($ch, CURLOPT_PROXY, self::$proxy);
}
curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent());
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 40);
curl_setopt($ch, CURLOPT_REFERER, $this->getReferrer());
/*curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);*/
sleep(mt_rand(10, 20));
$content = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->connectedURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
if (404 === $code) {
throw new CurlException('Content not found.');
}
if ($content === false) {
// there was a problem
$error = curl_error($ch);
throw new CurlException('Error retrieving "' . $url . '" (' . $error . ')');
}
if (false !== strpos($content, 'Error 525')) {
throw new CurlException('Error in a source site.');
}
return $content;
}
示例13: exec_curl_request
function exec_curl_request($handle)
{
$response = curl_exec($handle);
if ($response === false) {
$errno = curl_errno($handle);
$error = curl_error($handle);
error_log("Curl retornou um erro {$errno}: {$error}\n");
curl_close($handle);
return false;
}
$http_code = intval(curl_getinfo($handle, CURLINFO_HTTP_CODE));
curl_close($handle);
if ($http_code >= 500) {
// do not wat to DDOS server if something goes wrong
sleep(10);
return false;
} else {
if ($http_code != 200) {
$response = json_decode($response, true);
error_log("Request has failed with error {$response['error_code']}: {$response['description']}\n");
if ($http_code == 401) {
throw new Exception('Invalid access token provided');
}
return false;
} else {
$response = json_decode($response, true);
if (isset($response['description'])) {
error_log("Request was successfull: {$response['description']}\n");
}
$response = $response['result'];
}
}
return $response;
}
示例14: executeHttpRequest
/**
* @inheritdoc
*/
public function executeHttpRequest($url, $method = self::METHOD_GET, $data = [])
{
$ch = curl_init();
if ($method === self::METHOD_GET) {
if ($data) {
$query = $this->buildQuery($data);
if (strpos($url, '?') !== false) {
$url .= $query;
} else {
$url .= '?' . $query;
}
}
} else {
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
$body = curl_exec($ch);
$info = curl_getinfo($ch);
$code = $info['http_code'];
if ($code === 200) {
return $body;
} else {
$error = curl_errno($ch);
$msg = curl_error($ch);
throw new HttpException($code, sprintf('%s %s', $error, $msg));
}
}
示例15: curlExec
function curlExec($url, $data = false, $method = 'GET')
{
//global $JWT;
// global $_SITE;
if (!function_Exists('curl_init')) {
return false;
}
// $parseUrl = parse_url($url);
// if(!isset($parseUrl['scheme'])) {
// $url = $_SITE['CLIENT']['API'].$url;
// }
//$auth = $JWT->decode(SECURITY_TOKEN, SERVER_KEY);
$auth = "";
$headers = array("Accept: application/json", "Content-type: application/json");
$headers[] = "Authorization: NLAuth " . implode(', ', $auth);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($curl);
$info = curl_getinfo($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
return array('output' => $output, 'status' => $status, 'info' => $info);
}