当前位置: 首页>>代码示例>>PHP>>正文


PHP curl_error函数代码示例

本文整理汇总了PHP中curl_error函数的典型用法代码示例。如果您正苦于以下问题:PHP curl_error函数的具体用法?PHP curl_error怎么用?PHP curl_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了curl_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendPushNotificationToGCM

function sendPushNotificationToGCM($registration_ids, $message)
{
    $GCM_SERVER_API_KEY = $_ENV["GCM_SERVER_API_KEY"];
    $url = 'https://fcm.googleapis.com/fcm/send';
    $fields = array('registration_ids' => $registration_ids, 'data' => $message);
    // Update your Google Cloud Messaging API Key
    if (!defined('GOOGLE_API_KEY')) {
        define("GOOGLE_API_KEY", $GCM_SERVER_API_KEY);
    }
    $headers = array('Authorization: key=' . GOOGLE_API_KEY, 'Content-Type: application/json');
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    $result = curl_exec($ch);
    if ($result === FALSE) {
        die('Curl failed: ' . curl_error($ch));
    }
    curl_close($ch);
    return $result;
}
开发者ID:kousiksatish,项目名称:simple-gcm,代码行数:25,代码来源:internalgcmaccess.php

示例2: query

 public function query($method, $parameters = null)
 {
     $request = xmlrpc_encode_request($method, $parameters);
     $headers = array("Content-type: text/xml", "Content-length: " . strlen($request));
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $this->url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
     if ($this->timeout) {
         curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
     }
     $rawResponse = curl_exec($curl);
     $curlErrno = curl_errno($curl);
     $curlError = curl_error($curl);
     curl_close($curl);
     if ($curlErrno) {
         throw new NetworkException($curlError, $curlErrno);
     }
     $result = xmlrpc_decode($rawResponse);
     if (xmlrpc_is_fault($result)) {
         throw new NetworkException($result['faultString'], $result['faultCode']);
     }
     return $result;
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:25,代码来源:XmlRpcClient.class.php

示例3: 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);
 }
开发者ID:longceng,项目名称:honingwon,代码行数:47,代码来源:SnsNetwork.php

示例4: 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;
     }
 }
开发者ID:kosmosby,项目名称:medicine-prof,代码行数:28,代码来源:HttpConnection.class.php

示例5: getUserInfo

 public function getUserInfo()
 {
     $url = 'https://api.github.com/user?' . http_build_query(array('access_token' => $this->token->access_token));
     // Create a curl handle to a non-existing location
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     //Set curl to return the data instead of printing it to the browser.
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
     # timeout after 10 seconds, you can increase it
     curl_setopt($ch, CURLOPT_URL, $url);
     #set the url and get string together
     curl_setopt($ch, CURLOPT_USERAGENT, 'dukt-oauth');
     #set the url and get string together
     $json = '';
     if (($json = curl_exec($ch)) === false) {
         throw new \Exception(curl_error($ch));
     }
     curl_close($ch);
     $user = json_decode($json);
     if (!isset($user->id)) {
         throw new \Exception($json);
     }
     // Create a response from the request
     return array('uid' => $user->id, 'nickname' => $user->login, 'name' => $user->name, 'email' => $user->email, 'urls' => array('GitHub' => 'http://github.com/' . $user->login, 'Blog' => $user->blog));
 }
开发者ID:besimhu,项目名称:CraftCMS-Boilerplate,代码行数:27,代码来源:Github.php

示例6: 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;
 }
开发者ID:desmondmorris,项目名称:nike-php,代码行数:34,代码来源:Request.php

示例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;
 }
开发者ID:hypenotic,项目名称:slowfood,代码行数:32,代码来源:transport.php

示例8: _processXmlResponse

 private function _processXmlResponse($url, $xml = '')
 {
     /* 
     A private utility method used by other public methods to process XML responses.
     */
     if (extension_loaded('curl')) {
         $ch = curl_init() or die(curl_error());
         $timeout = 10;
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
         if (!empty($xml)) {
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
             curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml', 'Content-length: ' . strlen($xml)));
         }
         $data = curl_exec($ch);
         curl_close($ch);
         if ($data) {
             return new \SimpleXMLElement($data);
         } else {
             return false;
         }
     }
     if (!empty($xml)) {
         throw new Exception('Set xml, but curl does not installed.');
     }
     return simplexml_load_file($url);
 }
开发者ID:Kerion,项目名称:bbb-api,代码行数:32,代码来源:BigBlueButton.php

示例9: 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;
 }
开发者ID:nnrudakov,项目名称:glabs,代码行数:40,代码来源:ProxyCurl.php

示例10: _doRequest

 function _doRequest($method, $url, $vars)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_HEADER, 1);
     curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
     curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
     if ($method == 'POST') {
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
     }
     $data = curl_exec($ch);
     curl_close($ch);
     if ($data) {
         if ($this->callback) {
             $callback = $this->callback;
             $this->callback = false;
             return call_user_func($callback, $data);
         } else {
             return $data;
         }
     } else {
         return curl_error($ch);
     }
 }
开发者ID:juliano-hallac,项目名称:fabrik,代码行数:28,代码来源:sms.php

示例11: 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;
}
开发者ID:Anpix,项目名称:BoasVindasBot,代码行数:34,代码来源:index.php

示例12: fetchdata

function fetchdata($keyid, $uuid)
{
    $mydata = "<?xml version='1.0' encoding='UTF-8'?>\n<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>\n<soapenv:Body>\n<ns2:queryRQ xmlns:ns2='http://soap.fiap.org/'>\n<transport xmlns='http://gutp.jp/fiap/2009/11/'>\n<header>\n<query id='" . $uuid . "' type='storage'>\n<key id='{$keyid}' attrName='time' select='maximum' />\n</query>\n</header>\n</transport>\n</ns2:queryRQ>\n</soapenv:Body>\n</soapenv:Envelope>";
    $url = "http://161.200.90.122/axis2/services/FIAPStorage";
    $headers = array("Content-type: text/xml", "Content-length: " . strlen($mydata), "SOAPAction: http://soap.fiap.org/query");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $mydata);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    $data = curl_exec($ch);
    if ($data === false) {
        $error = curl_error($ch);
        echo $error;
        die('error occured');
    } else {
        $xml = simplexml_load_string($data);
        $ns = $xml->getNamespaces(true);
        $child = (string) $xml->children($ns['soapenv'])->Body->children($ns['ns2'])->queryRS->children($ns[''])->transport->body->point->value;
        $para[1] = $child;
        $child2 = (string) $xml->children($ns['soapenv'])->Body->children($ns['ns2'])->queryRS->children($ns[''])->transport->body->point->value->attributes();
        $para[2] = $child2;
    }
    curl_close($ch);
    return $para;
}
开发者ID:chart2023,项目名称:bems1,代码行数:29,代码来源:test2.php

示例13: responseMsg

 public function responseMsg()
 {
     //初始化curl
     $ch = curl_init() or die(curl_error());
     //echo "error1";
     //设置URL参数
     curl_setopt($ch, CURLOPT_URL, "http://www.yhkailun.com/?C=ShowTimes");
     //要求CURL返回数据
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     //执行请求
     $result = curl_exec($ch) or die(curl_error());
     //取得返回的结果,并显示  javascript:void(0);
     //echo $result;
     //echo curl_error($ch);
     //关闭CURL
     curl_close($ch);
     $pa = '%<div class="showTimesItem"*?>(.*?)<div id="footerHolderBar"*?>%si';
     preg_match_all($pa, $result, $match);
     $result = $match[1];
     $data = array();
     if (!empty($result)) {
         foreach ($result as $val) {
             $after = $this->pregstring($val);
             $last = $last . $after . "\n";
         }
     }
     $textTpl = "<a href='http://www.yhkailun.com/?C=ShowTimes'>楚门凯伦</a>\n咨询电话:81717555\n\n【影讯】\n" . $last . "\n";
     return $textTpl;
 }
开发者ID:sueflybaby,项目名称:learngit,代码行数:29,代码来源:theaterkailun.class.php

示例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));
     }
 }
开发者ID:kollway-app,项目名称:wechat-pay,代码行数:35,代码来源:CurlHttpClient.php

示例15: send

 public function send($payload)
 {
     $headers = array('Content-Type: application/x-www-form-urlencoded');
     $post_string = http_build_query($payload);
     $cacertPath = dirname(__FILE__) . '/cacert.pem';
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->config->apiAddress);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     if (file_exists($cacertPath)) {
         $this->log('cacert.pem file found, verifying API endpoint');
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
         curl_setopt($ch, CURLOPT_CAINFO, $cacertPath);
     } else {
         $this->log('cacert.pem file not found, the API endpoint will not be verified', true);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     }
     curl_exec($ch);
     $curl_error = curl_error($ch);
     $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if ($http_code !== 200) {
         throw new \Exception('cURL error code ' . $http_code . ': ' . $curl_error);
     }
 }
开发者ID:usabilitydynamics,项目名称:wp-php-console,代码行数:27,代码来源:Client.php


注:本文中的curl_error函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。