當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Curl::error方法代碼示例

本文整理匯總了PHP中Curl::error方法的典型用法代碼示例。如果您正苦於以下問題:PHP Curl::error方法的具體用法?PHP Curl::error怎麽用?PHP Curl::error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Curl的用法示例。


在下文中一共展示了Curl::error方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: sendRequest

 private function sendRequest($url, $method, $headers = null, $body = null)
 {
     $this->curl->headers = array();
     $this->curl->options = array();
     $this->curl->options['CURLOPT_SSL_VERIFYHOST'] = false;
     $this->curl->options['CURLOPT_SSL_VERIFYPEER'] = false;
     $this->curl->headers['Accept'] = VMware_VCloud_SDK_Constants::VCLOUD_ACCEPT_HEADER . ';' . 'version=' . $this->apiVersion;
     if ($this->authToken) {
         $this->curl->headers[VMware_VCloud_SDK_Constants::VCLOUD_AUTH_TOKEN] = $this->authToken;
     } else {
         $this->curl->options['CURLOPT_USERPWD'] = $this->username . ':' . $this->password;
     }
     if ($headers) {
         $h = $this->curl->headers;
         $h = array_merge($h, $headers);
         $this->curl->headers = $h;
     }
     $response = $this->curl->{$method}($url, $body);
     //  var_dump($url,$method,$this->curl,$body);
     if (!is_object($response) && $this->curl->error()) {
         // var_dump($url,$method,$headers,$body,$this->curl);
         throw new Exception($this->curl->error());
     }
     if (!$this->authToken) {
         $this->authToken = $response->headers[VMware_VCloud_SDK_Constants::VCLOUD_AUTH_TOKEN];
     }
     return $response;
 }
開發者ID:rhizalpatrax64bit,項目名稱:StacksNetwork,代碼行數:28,代碼來源:MyCurlClient.php

示例2: testEnsureGettingErrorReturnsCorrectInfo

 function testEnsureGettingErrorReturnsCorrectInfo()
 {
     $curl = new Curl(self::TEST_VALID_URL);
     $this->assertEquals(0, $curl->errno());
     $this->assertEquals('', $curl->error());
     $curl->setopt(CURLOPT_RETURNTRANSFER, 1);
     $curl->setopt(CURLOPT_PROXY, $this->proxy);
     $curl->exec();
     $this->assertEquals(0, $curl->errno());
     $this->assertEquals('', $curl->error());
 }
開發者ID:schwarer2006,項目名稱:wikia,代碼行數:11,代碼來源:CurlTest.php

示例3: testError

 function testError()
 {
     $curl = new Curl();
     $curl->get('diaewkaksdljf-invalid-url-dot-com.com');
     $err = $curl->error();
     $this->assertTrue(!empty($err));
 }
開發者ID:nickl-,項目名稱:curl,代碼行數:7,代碼來源:CurlTest.php

示例4: getProblemInfo

 public static function getProblemInfo($problemId)
 {
     // 新建一個curl
     $ch = new Curl();
     $url = 'http://poj.org/problem?id=' . $problemId;
     $html = $ch->get($url);
     if (empty($html) || $ch->error()) {
         $ch->close();
         return false;
     }
     $ch->close();
     $problemInfo = array();
     $matches = array();
     // 獲取標題
     preg_match('/<div class="ptt" lang="en-US">(.*)<\\/div>/sU', $html, $matches);
     $problemInfo['title'] = '';
     if (!empty($matches[1])) {
         $problemInfo['title'] = trim($matches[1]);
     }
     // 獲取來源
     preg_match('/<a href="searchproblem\\?field=source.*>(.*)<\\/a>/sU', $html, $matches);
     $problemInfo['source'] = '';
     if (!empty($matches[1])) {
         $problemInfo['source'] = trim($matches[1]);
     }
     $problemInfo['problem_id'] = $problemId;
     $problemInfo['problem_code'] = $problemId;
     return $problemInfo;
 }
開發者ID:aozhongxu,項目名稱:web_hqoj,代碼行數:29,代碼來源:PojRemoteAdapter.class.php

示例5: getProblemInfo

 public static function getProblemInfo($problemId)
 {
     // 新建一個curl
     $ch = new Curl();
     $url = 'http://acm.hdu.edu.cn/showproblem.php?pid=' . $problemId;
     $html = $ch->get($url);
     if (empty($html) || $ch->error()) {
         $ch->close();
         return false;
     }
     $ch->close();
     $problemInfo = array();
     $matches = array();
     // 獲取標題
     preg_match('/<td align=center><h1 style=\'color:#1A5CC8\'>(.*)<\\/h1>/sU', $html, $matches);
     $problemInfo['title'] = '';
     if (!empty($matches[1])) {
         $problemInfo['title'] = trim($matches[1]);
         $problemInfo['title'] = iconv('GBK', 'UTF-8', $problemInfo['title']);
     }
     // 獲取來源
     preg_match('/>Source.*<a.*\\/search.php.*>(.*)<\\/a>/sU', $html, $matches);
     $problemInfo['source'] = '';
     if (!empty($matches[1])) {
         $problemInfo['source'] = trim($matches[1]);
         $problemInfo['source'] = iconv('GBK', 'UTF-8', $problemInfo['source']);
     }
     $problemInfo['problem_id'] = $problemId;
     $problemInfo['problem_code'] = $problemId;
     return $problemInfo;
 }
開發者ID:aozhongxu,項目名稱:web_hqoj,代碼行數:31,代碼來源:HduRemoteAdapter.class.php

示例6: get

 public function get($url_mixed, $data = array())
 {
     if (is_array($url_mixed)) {
         $curl_multi = curl_multi_init();
         $this->multi_parent = true;
         $this->curls = array();
         foreach ($url_mixed as $url) {
             $curl = new Curl();
             $curl->multi_child = true;
             $curl->beforeSend($this->before_send_function);
             $curl->success($this->success_function);
             $curl->error($this->error_function);
             $curl->complete($this->complete_function);
             $curl->base_url = $url;
             $curl->url = $this->buildURL($url, $data);
             $curl->setOpt(CURLOPT_URL, $curl->url, $curl->curl);
             $curl->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
             $curl->setOpt(CURLOPT_HTTPGET, true);
             $this->curls[] = $curl;
             $curlm_error_code = curl_multi_add_handle($curl_multi, $curl->curl);
             if (!($curlm_error_code === CURLM_OK)) {
                 throw new \ErrorException('cURL multi add handle error: ' . curl_multi_strerror($curlm_error_code));
             }
         }
         foreach ($this->curls as $ch) {
             foreach ($this->options as $key => $value) {
                 $ch->setOpt($key, $value);
             }
         }
         do {
             curl_multi_select($curl_multi);
             $status = curl_multi_exec($curl_multi, $active);
         } while ($status === CURLM_CALL_MULTI_PERFORM || $active);
         while (!($info_array = curl_multi_info_read($curl_multi)) === false) {
             if (!($info_array['msg'] === CURLMSG_DONE)) {
                 continue;
             }
             foreach ($this->curls as $ch) {
                 if ($ch->curl === $info_array['handle']) {
                     $ch->curl_error_code = $info_array['result'];
                     break;
                 }
             }
         }
         foreach ($this->curls as $ch) {
             $this->exec($ch);
         }
     } else {
         $this->base_url = $url_mixed;
         $this->url = $this->buildURL($url_mixed, $data);
         $this->setOpt(CURLOPT_URL, $this->url);
         $this->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
         $this->setOpt(CURLOPT_HTTPGET, true);
         return $this->exec();
     }
 }
開發者ID:andela-fadebayo,項目名稱:paga-demo,代碼行數:56,代碼來源:curl.php

示例7: getProblemInfo

 public static function getProblemInfo($problemCode)
 {
     // 新建一個curl
     $ch = new Curl();
     $url = 'http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=' . $problemCode;
     $html = $ch->get($url);
     if (empty($html) || $ch->error()) {
         $ch->close();
         return false;
     }
     $ch->close();
     $problemInfo = array();
     $matches = array();
     // 獲取標題
     preg_match('/<span class="bigProblemTitle">(.*)<\\/span>/sU', $html, $matches);
     $problemInfo['title'] = '';
     if (!empty($matches[1])) {
         $problemInfo['title'] = trim($matches[1]);
     }
     // 獲取來源
     preg_match('/Source:.*<strong>(.*)<\\/strong>/sU', $html, $matches);
     if (empty($matches[1])) {
         preg_match('/Contest:.*<strong>(.*)<\\/strong>/sU', $html, $matches);
     }
     $problemInfo['source'] = '';
     if (!empty($matches[1])) {
         $problemInfo['source'] = trim($matches[1]);
     }
     // 獲取$problemId
     preg_match('/"\\/onlinejudge\\/submit.do\\?problemId=(\\d+)"/sU', $html, $matches);
     $problemInfo['problem_id'] = 0;
     if (!empty($matches[1])) {
         $problemInfo['problem_id'] = $matches[1];
     }
     $problemInfo['problem_code'] = $problemCode;
     $problemInfo['remote'] = StatusVars::REMOTE_ZOJ;
     return $problemInfo;
 }
開發者ID:aozhongxu,項目名稱:web_hqoj,代碼行數:38,代碼來源:ZojRemoteAdapter.class.php

示例8: testErrorCallback

 public function testErrorCallback()
 {
     $success_called = FALSE;
     $error_called = FALSE;
     $complete_called = FALSE;
     $curl = new Curl();
     $curl->setHeader('X-DEBUG-TEST', 'get');
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, FALSE);
     $curl->setOpt(CURLOPT_SSL_VERIFYHOST, FALSE);
     $curl->setOpt(CURLOPT_CONNECTTIMEOUT_MS, 2000);
     $curl->success(function ($instance) use(&$success_called, &$error_called, &$complete_called) {
         PHPUnit_Framework_Assert::assertInstanceOf('Curl', $instance);
         PHPUnit_Framework_Assert::assertFalse($success_called);
         PHPUnit_Framework_Assert::assertFalse($error_called);
         PHPUnit_Framework_Assert::assertFalse($complete_called);
         $success_called = TRUE;
     });
     $curl->error(function ($instance) use(&$success_called, &$error_called, &$complete_called, &$curl) {
         PHPUnit_Framework_Assert::assertInstanceOf('Curl', $instance);
         PHPUnit_Framework_Assert::assertFalse($success_called);
         PHPUnit_Framework_Assert::assertFalse($error_called);
         PHPUnit_Framework_Assert::assertFalse($complete_called);
         $error_called = TRUE;
     });
     $curl->complete(function ($instance) use(&$success_called, &$error_called, &$complete_called) {
         PHPUnit_Framework_Assert::assertInstanceOf('Curl', $instance);
         PHPUnit_Framework_Assert::assertFalse($success_called);
         PHPUnit_Framework_Assert::assertTrue($error_called);
         PHPUnit_Framework_Assert::assertFalse($complete_called);
         $complete_called = TRUE;
     });
     $curl->get(Test::ERROR_URL);
     $this->assertFalse($success_called);
     $this->assertTrue($error_called);
     $this->assertTrue($complete_called);
 }
開發者ID:canerdogan,項目名稱:php-curl-class,代碼行數:36,代碼來源:run.php

示例9: die_and_log

    }
}
if (is_null($length)) {
    die_and_log($status = 400, "unknown content size:", $url);
}
if ($length > MAX_SIZE) {
    die_and_log($status = 400, "content size over: " . MAX_SIZE . "<{$length}bytes", $url);
}
if (!preg_match("/\\Aimage\\/(png|jpeg|gif)\\z/ui", $content_type)) {
    die_and_log($status = 400, "not support content type:" . $content_type, $url);
}
// get access
$c = new Curl();
$c->setHeader('X-Forwarded-For', getRemoteIP());
$c->error(function () {
    die_and_log($status = 500, "get request error");
});
$c->get($url);
// dump
header("Content-Type: {$content_type}");
echo $c->response;
//--functions--
function die_and_log($status = 400, $str = '', $extra = '')
{
    header("HTTP/1.1 {$status} Error");
    echo $str;
    error_log("{$str} :: {$extra}");
    exit;
}
function getRemoteIP()
{
開發者ID:syossan27,項目名稱:JS_LGTM_Editor,代碼行數:31,代碼來源:proxy.php


注:本文中的Curl::error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。