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


PHP curl_strerror函数代码示例

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


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

示例1: file_get_html_with_retry

function file_get_html_with_retry($url, $retrytimes = 5, $timeoutsec = 1)
{
    global $errormsg;
    $errno = 0;
    for ($loopcount = 0; $loopcount < $retrytimes; $loopcount++) {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36");
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeoutsec);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeoutsec);
        curl_setopt($ch, CURLOPT_FAILONERROR, true);
        $contents = curl_exec($ch);
        //var_dump($contents); //debug
        if ($contents !== false) {
            curl_close($ch);
            break;
        }
        $errno = curl_errno($ch);
        $errormsg = curl_error($ch);
        print $timeoutsec;
        curl_close($ch);
    }
    if ($loopcount === $retrytimes) {
        $error_message = curl_strerror($errno);
        print 'http connection error : ' . $error_message . ' url : ' . $url . "\n";
    }
    return $contents;
}
开发者ID:bee7813993,项目名称:save_webradio,代码行数:29,代码来源:onsen_idlist.php

示例2: call

 /**
  * @param Request $request
  * @return Response
  */
 public function call(Request $request)
 {
     // Create cURL
     $ch = curl_init();
     // Set-up URL
     curl_setopt($ch, CURLOPT_URL, $request->getUrl());
     // Set-up headers
     $headers = $request->getHeaders();
     array_walk($headers, function (&$item, $key) {
         $item = "{$key}: {$item}";
     });
     curl_setopt($ch, CURLOPT_HTTPHEADER, array_values($headers));
     // Set-up others
     curl_setopt_array($ch, $request->getOpts());
     // Receive result
     $result = curl_exec($ch);
     // Parse response
     $response = new Response();
     if ($result === FALSE) {
         $response->setError(curl_strerror(curl_errno($ch)));
         $response->setData(FALSE);
         $response->setCode(curl_errno($ch));
         $response->setHeaders(curl_getinfo($ch));
     } else {
         $response->setData(json_decode($result));
         $response->setCode(curl_getinfo($ch, CURLINFO_HTTP_CODE));
         $response->setHeaders(curl_getinfo($ch));
     }
     // Close cURL
     curl_close($ch);
     return $response;
 }
开发者ID:r01261,项目名称:GopayInline,代码行数:36,代码来源:Curl.php

示例3: push

 /**
  * @param $uri
  * @param $target type of notification
  * @param $delay immediate, in 450sec or in 900sec
  * @param $messageId The optional custom header X-MessageID uniquely identifies a notification message. If it is present, the same value is returned in the notification response. It must be a string that contains a UUID
  * @param $message The message to send
  *
  * @throws PushException
  * @return array
  */
 private function push($uri, $target, $delay, $messageId, $message)
 {
     $headers = array('Content-Type: text/xml', 'Accept: application/*', "X-NotificationClass: {$delay}");
     if ($messageId != NULL) {
         $headers[] = "X-MessageID: {$messageId}";
     }
     if ($target != NULL) {
         $headers[] = "X-WindowsPhone-Target:{$target}";
     }
     $request = curl_init();
     curl_setopt($request, CURLOPT_HEADER, true);
     curl_setopt($request, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($request, CURLOPT_POST, true);
     curl_setopt($request, CURLOPT_POSTFIELDS, $message);
     curl_setopt($request, CURLOPT_URL, $uri);
     curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
     $response = curl_exec($request);
     if ($errorNumber = curl_errno($request)) {
         $errorMessage = curl_strerror($errorNumber);
         throw new PushException($errorMessage, $errorNumber);
     }
     curl_close($request);
     $result = array();
     foreach (explode("\n", $response) as $line) {
         $tab = explode(":", $line, 2);
         if (count($tab) == 2) {
             $result[$tab[0]] = trim($tab[1]);
         }
     }
     return $result;
 }
开发者ID:jildertmiedema,项目名称:windows-phone-push,代码行数:41,代码来源:WindowsPhonePushNotification.php

示例4: crudAction

 public function crudAction($action = 'create')
 {
     switch ($action) {
         case 'create':
             curl_setopt($this->curlHandler, CURLOPT_CUSTOMREQUEST, "POST");
             break;
         case 'update':
             curl_setopt($this->curlHandler, CURLOPT_CUSTOMREQUEST, "PUT");
             break;
         case 'read':
             curl_setopt($this->curlHandler, CURLOPT_CUSTOMREQUEST, "GET");
             break;
         case 'delete':
             curl_setopt($this->curlHandler, CURLOPT_CUSTOMREQUEST, "DELETE");
             break;
     }
     if (!empty($this->jsonData)) {
         curl_setopt($this->curlHandler, CURLOPT_POSTFIELDS, $this->jsonData);
     }
     curl_setopt($this->curlHandler, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($this->curlHandler, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($this->jsonData)));
     $this->apiReponse = curl_exec($this->curlHandler);
     if ($errno = curl_errno($this->curlHandler)) {
         $error_message = curl_strerror($errno);
         echo "cURL error ({$errno}):\n {$error_message}";
     }
     curl_close($this->curlHandler);
 }
开发者ID:kamranshahzad,项目名称:passbook-ui,代码行数:28,代码来源:client-api.php

示例5: post

 public static function post($url, $postFields = null, $headers = null)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_FAILONERROR, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($postFields) ? self::getPostHttpBody($postFields) : $postFields);
     if (self::$readTimeout) {
         curl_setopt($ch, CURLOPT_TIMEOUT, self::$readTimeout);
     }
     if (self::$connectTimeout) {
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::$connectTimeout);
     }
     // https request
     if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     }
     if (is_array($headers) && 0 < count($headers)) {
         $httpHeaders = self::getHttpHearders($headers);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
     }
     $httpResponse = new HttpResponse();
     $httpResponse->setBody(curl_exec($ch));
     $httpResponse->setStatus(curl_getinfo($ch, CURLINFO_HTTP_CODE));
     if ($errno = curl_errno($ch)) {
         throw new Exception(curl_strerror($errno));
     }
     curl_close($ch);
     return $httpResponse->getBody();
 }
开发者ID:rainwsy,项目名称:aliyundm,代码行数:32,代码来源:HttpHelper.php

示例6: connect

 public function connect()
 {
     $this->open();
     $sendData = $this->serializeParams($this->getParameters());
     curl_setopt($this->curl, CURLOPT_URL, "{$this->url}?{$sendData}");
     //curl_setopt($this->curl, CURLOPT_POST, true); // HTTP POST
     //curl_setopt($this->curl, CURLOPT_POSTFIELDS, $sendData);
     $response = curl_exec($this->curl);
     if ($response === false) {
         $errno = @curl_errno($this->curl);
         $error = @curl_strerror($errno);
         $this->close();
         throw TransferException::couldNotTransferData($this->url . ($this->isProxy() ? ' (usando proxy)' : ''), "[{$errno}] {$error}");
     }
     list($response_headers_str, $response) = explode("\r\n\r\n", $response);
     /*$response_headers = $this->_readHeaders($response_headers_str);
       if (!$this->checkResponseToken($response_headers['X-FW-Response'])) {
           throw new WrongDataTransferException('Resposta inv�lida do servidor, entre em contato com a Furac�o');
       }*/
     $this->close();
     if (empty($response)) {
         throw TransferException::emptyDataReturned();
     }
     return $response;
 }
开发者ID:brodaproject,项目名称:broda,代码行数:25,代码来源:Curl.php

示例7: getErrorMessage

 public function getErrorMessage()
 {
     if ($this->errNo) {
         return curl_strerror($this->errNo);
     }
     return null;
 }
开发者ID:ugursogukpinar,项目名称:o365graph-sdk,代码行数:7,代码来源:RequestManager.php

示例8: __construct

 /**
  * @param string|null $message
  */
 public function __construct(RequestInterface $request, Response $response, $message = null)
 {
     $this->request = $request;
     $this->response = $response;
     if ($message === null) {
         $curlError = $response->getHeader('X-Curl-Error-Result');
         $message = sprintf('HTTP %s request to "%s%s" failed: %d - "%s".', $request->getMethod(), $request->getHost(), $request->getResource(), $curlError ?: $response->getStatusCode(), $curlError ? curl_strerror($curlError) : $response->getReasonPhrase());
     }
     parent::__construct($message);
 }
开发者ID:vaniocz,项目名称:VanioBuzzBundle,代码行数:13,代码来源:RequestFailedException.php

示例9: createResultCollection

 /**
  * createResultCollection.
  *
  * @param bool $hasError
  */
 public function createResultCollection($hasError = false)
 {
     $errorLog = null;
     if ($hasError) {
         $errorLog = curl_strerror(5);
     }
     $result = new Result($this->createUrlInfo(), $hasError ? 400 : 200, 0.42, $errorLog);
     $resultCollection = new ResultCollection();
     $resultCollection->append($result);
     return $resultCollection;
 }
开发者ID:hogosha,项目名称:monitor,代码行数:16,代码来源:CsvRendererTest.php

示例10: execute

 private function execute($curl)
 {
     $body = curl_exec($curl);
     if ($errno = curl_errno($curl)) {
         $error_message = curl_strerror($errno);
         throw new HttpException("cURL error ({$errno}): {$error_message}", 0, $this->url);
     }
     $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     $contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
     curl_close($curl);
     return array($statusCode, $contentType, $body);
 }
开发者ID:benjaminpick,项目名称:web-service-common-php,代码行数:12,代码来源:CurlRequest.php

示例11: processCommand

 /**
  * Performs Aspose Api Request.
  *
  * @param string $url Target Aspose API URL.
  * @param string $method Method to access the API such as GET, POST, PUT and DELETE
  * @param string $headerType XML or JSON
  * @param string $src Post data.
  * @param string $returnType
  * @return string
  * @throws Exception
  */
 public static function processCommand($url, $method = 'GET', $headerType = 'XML', $src = '', $returnType = 'xml')
 {
     $dispatcher = AsposeApp::getEventDispatcher();
     $method = strtoupper($method);
     $headerType = strtoupper($headerType);
     AsposeApp::getLogger()->info("Aspose Cloud SDK: processCommand called", array('url' => $url, 'method' => $method, 'headerType' => $headerType, 'src' => $src, 'returnType' => $returnType));
     $session = curl_init();
     curl_setopt($session, CURLOPT_URL, $url);
     if ($method == 'GET') {
         curl_setopt($session, CURLOPT_HTTPGET, 1);
     } else {
         curl_setopt($session, CURLOPT_POST, 1);
         curl_setopt($session, CURLOPT_POSTFIELDS, $src);
         curl_setopt($session, CURLOPT_CUSTOMREQUEST, $method);
     }
     curl_setopt($session, CURLOPT_HEADER, false);
     if ($headerType == 'XML') {
         curl_setopt($session, CURLOPT_HTTPHEADER, array('Accept: application/' . $returnType . '', 'Content-Type: application/xml', 'x-aspose-client: PHPSDK/v1.0'));
     } else {
         curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'x-aspose-client: PHPSDK/v1.0'));
     }
     curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
     if (preg_match('/^(https)/i', $url)) {
         curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
     }
     // Allow users to register curl options before the call is executed
     $event = new ProcessCommandEvent($session);
     $dispatcher->dispatch(ProcessCommandEvent::PRE_CURL, $event);
     $result = curl_exec($session);
     $headers = curl_getinfo($session);
     if (substr($headers['http_code'], 0, 1) != '2') {
         if (curl_errno($session) !== 0) {
             throw new AsposeCurlException(curl_strerror(curl_errno($session)), $headers, curl_errno($session));
             AsposeApp::getLogger()->warning(curl_strerror(curl_errno($session)));
         } else {
             throw new Exception($result);
             AsposeApp::getLogger()->warning($result);
         }
     } else {
         if (preg_match('/You have processed/i', $result) || preg_match('/Your pricing plan allows only/i', $result)) {
             AsposeApp::getLogger()->alert($result);
             throw new Exception($result);
         }
     }
     // Allow users to alter the result
     $event = new ProcessCommandEvent($session, $result);
     /** @var ProcessCommandEvent $dispatchedEvent */
     $dispatchedEvent = $dispatcher->dispatch(ProcessCommandEvent::POST_CURL, $event);
     curl_close($session);
     // TODO test or the Event result needs to be returned in case an listener was triggered
     return $dispatchedEvent->getResult();
 }
开发者ID:jasonpranevicius,项目名称:Aspose_Cloud_SDK_For_PHP,代码行数:63,代码来源:Utils.php

示例12: sendRequest

 /**
  * Curl request to giving url
  *
  * @param string $url
  * @param array $param
  * 
  * @return array
  */
 public function sendRequest($url, $param)
 {
     $curl = curl_init($url);
     curl_setopt_array($curl, array(CURLOPT_VERBOSE => 1, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $param));
     $getResult = curl_exec($curl);
     if ($errno = curl_errno($curl)) {
         $message = curl_strerror($errno);
         throw new CurlErrorException("CURL error : {$message}");
     }
     curl_close($curl);
     parse_str($getResult, $result);
     return $result;
 }
开发者ID:heinzawhtet,项目名称:myanpay,代码行数:21,代码来源:AbstractRequest.php

示例13: doRequest

 /**
  * Process API requests to github and packagist
  *
  * @param $url
  * @param array $headers
  * @return mixed
  */
 private static function doRequest($url, $headers = [])
 {
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     $response = curl_exec($ch);
     if (0 !== ($errno = curl_errno($ch))) {
         $errorMessage = curl_strerror($errno);
         Yii::$app->session->setFlash("cURL error ({$errno}):\n {$errorMessage}");
     }
     curl_close($ch);
     return $response;
 }
开发者ID:DevGroup-ru,项目名称:yii2-extensions-manager,代码行数:23,代码来源:ExtensionsController.php

示例14: __construct

 /**
  * @param array $messages - array of [$request, $response]
  * @param string|null $errorMessage
  */
 public function __construct(array $messages, $errorMessage = null)
 {
     $this->messages = $messages;
     $errorMessages = [];
     if ($errorMessage === null) {
         foreach ($this->messages as $messages) {
             /** @var RequestInterface $request */
             /** @var Response $response */
             list($request, $response) = $messages;
             $curlError = $response->getHeader('X-Curl-Error-Result');
             $errorMessages[] = sprintf('%s "%s%s": %d - "%s"', $request->getMethod(), $request->getHost(), $request->getResource(), $curlError ?: $response->getStatusCode(), $curlError ? curl_strerror($curlError) : $response->getReasonPhrase());
         }
         $errorMessage = sprintf("Batch HTTP requests failed.\n - %s.", implode("\n - ", $errorMessages));
     }
     list($request, $response) = current($this->messages);
     parent::__construct($request, $response, $errorMessage);
 }
开发者ID:vaniocz,项目名称:VanioBuzzBundle,代码行数:21,代码来源:BatchRequestFailedException.php

示例15: testCurlErrors

 public function testCurlErrors()
 {
     $expectedErrorCodeByDomain = array('' => CURLE_URL_MALFORMAT, 'foo://bar' => CURLE_UNSUPPORTED_PROTOCOL, 'http://non-existing-domain' => CURLE_COULDNT_RESOLVE_HOST, 'https://expired.badssl.com' => CURLE_SSL_CACERT);
     foreach ($expectedErrorCodeByDomain as $domain => $expectedErrorCode) {
         try {
             $this->connection->get($domain, []);
         } catch (ErrorException $e) {
             $expectedErrorMessage = 'cURL error ' . $expectedErrorCode;
             if (function_exists('curl_strerror')) {
                 $expectedErrorMessage .= ' (' . curl_strerror($expectedErrorCode) . ')';
             }
             $this->assertEquals($expectedErrorMessage, $e->getMessage());
             continue;
         }
         $this->fail('An expected exception has not been raised');
     }
 }
开发者ID:Ingenico-ePayments,项目名称:connect-sdk-php,代码行数:17,代码来源:DefaultConnectionTest.php


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