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


PHP Curl类代码示例

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


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

示例1: init

 /**
  * 初始化
  */
 public static function init()
 {
     $object = new Curl();
     $object->cookiePath();
     //初始cookie路径
     return $object;
 }
开发者ID:huangxinchun,项目名称:phalcon-modules,代码行数:10,代码来源:Curl.php

示例2: nextSong

 /**
  * get the next song in the playlist
  */
 private function nextSong()
 {
     $curl = new Curl();
     $songArray = $curl->getArray("http://8tracks.com/sets/" . $this->playToken . "/next?mix_id=" . $this->mixId . "&api_version=2&format=jsonh");
     $status = $songArray["status"];
     if (!preg_match('/(200)/', $status)) {
         if (preg_match('/(403)/', $status)) {
             $this->output->error("8tracks made a boo boo. (" . $status . ")", 403);
         } else {
             $this->output->error("8tracks made a boo boo. (" . $status . ")");
         }
     }
     if (isset($songArray["set"]["track"]["id"])) {
         $songId = $songArray["set"]["track"]["id"];
         $title = $songArray["set"]["track"]["name"];
         $artist = $songArray["set"]["track"]["performer"];
         $album = $songArray["set"]["track"]["release_name"];
         $duration = $songArray["set"]["track"]["play_duration"];
         $songUrl = $songArray["set"]["track"]["url"];
         $song = $this->db->select("SELECT mixId FROM 8tracks_playlists_songs WHERE mixId=? AND songId=? LIMIT 1", array($this->mixId, $songId), array("%d", "%d"));
         if (empty($song)) {
             $this->db->insert("8tracks_playlists_songs", array("mixId" => $this->mixId, "songId" => $songId, "trackNumber" => $this->trackNumber), array("%d", "%d", "%d"));
             $song = $this->db->select("SELECT songId FROM 8tracks_songs WHERE songId=? LIMIT 1", array($songId), array("%d"));
             if (empty($song)) {
                 $this->db->insert("8tracks_songs", array("songId" => $songId, "title" => $title, "artist" => $artist, "album" => $album, "duration" => $duration, "songUrl" => $songUrl), array("%d", "%s", "%s", "%s", "%d", "%s"));
             }
         }
     } else {
         $this->output->error("That's all we could find.");
     }
 }
开发者ID:5eiko,项目名称:psychic-rotary-phone,代码行数:34,代码来源:EightTracks.php

示例3: getIp

 public static function getIp()
 {
     $co = new Curl(self::$ifconfigIp);
     $co->setopt(CURLOPT_RETURNTRANSFER, true);
     $ip = $co->exec();
     return $ip;
 }
开发者ID:braph,项目名称:dottk,代码行数:7,代码来源:ifconfig.php

示例4: 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

示例5: safeRemove

 /**
  * @param Curl $ch
  *
  * @throws \Exception
  */
 private function safeRemove(Curl $ch)
 {
     $return = curl_multi_remove_handle($this->multiHandle, $ch->getHandle());
     if ($return !== 0) {
         throw new \Exception('Error occurred: ' . $return);
     }
 }
开发者ID:chenshuhao,项目名称:BeginShake,代码行数:12,代码来源:MultiCurl.php

示例6: expressTakeUp

 public function expressTakeUp($userID, $expressID)
 {
     $curl = new Curl();
     $data = array("expressID" => $expressID, "userID" => $userID);
     $curl->post($this->url['expressTake'], $data);
     return $curl->response;
 }
开发者ID:aslijiasheng,项目名称:jasongo,代码行数:7,代码来源:express_service_model.php

示例7: 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

示例8: testValidatedSsl

 function testValidatedSsl()
 {
     $curl = new Curl();
     $curl->setValidateSsl(true);
     $response = $curl->get('https://www.facebook.com/');
     $this->assertEquals(200, $response->headers['Status-Code']);
 }
开发者ID:nickl-,项目名称:curl,代码行数:7,代码来源:CurlTest.php

示例9: doRequest

 public function doRequest($url)
 {
     $url = Util::sanitizeURL($url);
     if (false && !Util::validateURL($url)) {
         $response = array('errorCode' => 1008, 'errorMsg' => _('Invalid url') . $url);
         $this->sendJSON($response);
     }
     $curl = new Curl($url);
     // real url after all redirects.
     $url = $curl->getRealUrl();
     $qid = Util::generateQid($url);
     $outfile = Config::$outputDir . "/{$qid}.png";
     if (!file_exists($outfile)) {
         if (!$curl->isReachable()) {
             $response = array('errorCode' => 1009, 'errorMsg' => _('Site is unreachable please try again later'));
             $this->sendJSON($response);
         }
     }
     if ($this->queueRequest($qid, $url)) {
         Log::info("Queue {$url}");
         $response = array('items' => array(array('title' => $curl->getTitle(), 'qid' => $qid)));
         $this->sendJSON($response);
     } else {
         $response = array('errorCode' => 1009, 'errorMsg' => sprintf(_('Error: %s'), $this->db->error));
         $this->sendJSON($response);
     }
 }
开发者ID:rhalff,项目名称:Websnapit,代码行数:27,代码来源:websnap.php

示例10: initialize

 function initialize()
 {
     if (!$this->fetched) {
         $config =& get_config();
         $assetUrl = $config['asset_service'] . $this->node['AssetID'];
         $curl = new Curl();
         $curl->create($assetUrl);
         $curl->option(CURLOPT_HEADER, true);
         $curl->option(CURLOPT_NOBODY, true);
         $response = $curl->execute();
         if ($response) {
             $headers = http_parse_headers($response);
             $this->size = $headers['Content-Length'];
             $this->contentType = $headers['Content-Type'];
             if (isset($headers['ETag'])) {
                 $this->etag = $headers['ETag'];
             } else {
                 if (isset($headers['Etag'])) {
                     $this->etag = $headers['Etag'];
                 } else {
                     $this->etag = '';
                 }
             }
         } else {
             log_message('error', "InventoryFile: Failed to fetch headers from {$assetUrl}");
         }
         $this->fetched = true;
     }
 }
开发者ID:QuillLittlefeather,项目名称:mgm-simiangrid,代码行数:29,代码来源:Class.InventoryFile.php

示例11: test_error

 function test_error()
 {
     assert_throws('CurlException', function () {
         $curl = new Curl();
         $curl->get('diaewkaksdljf-invalid-url-dot-com.com');
     });
 }
开发者ID:leebivip,项目名称:dns,代码行数:7,代码来源:curl_test.php

示例12: 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->setOpt(CURLOPT_URL, $this->_buildURL($url, $data), $curl->curl);
             $curl->setOpt(CURLOPT_HTTPGET, true);
             $this->_call($this->_before_send, $curl);
             $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 {
             $status = curl_multi_exec($curl_multi, $active);
         } while ($status === CURLM_CALL_MULTI_PERFORM || $active);
         foreach ($this->curls as $ch) {
             $this->exec($ch);
         }
     } else {
         $this->setopt(CURLOPT_URL, $this->_buildURL($url_mixed, $data));
         $this->setopt(CURLOPT_HTTPGET, true);
         return $this->exec();
     }
 }
开发者ID:AlexBGD,项目名称:DrKaske,代码行数:35,代码来源:Curl.php

示例13: CallMethod

 /**
  * Вызов метода ApiVK
  * @param $sMethod
  * @param $mParams
  * @return bool|mixed
  */
 private function CallMethod($sMethod, $mParams)
 {
     if (is_array($mParams)) {
         if (!isset($mParams['access_token'])) {
             if (!$this->sAccessToken) {
                 return false;
             }
             $mParams['access_token'] = $this->sAccessToken;
         }
         $oCurl = new Curl();
         $oCurl->SetUrl('https://api.vk.com/method/' . $sMethod);
         $oCurl->SetPostfields($mParams);
         $sResult = $oCurl->GetResponseBody(true);
     } else {
         $sParams = $mParams;
         if (!strpos($mParams, 'access_token')) {
             if (!$this->sAccessToken) {
                 return false;
             }
             $sParams = $mParams . '&access_token=' . $this->sAccessToken;
         }
         $oCurl = new Curl();
         $oCurl->SetUrl('https://api.vk.com/method/' . $sMethod . '?' . $sParams);
         $sResult = $oCurl->GetResponseBody(true);
     }
     if ($sResult === false) {
         throw new Exception($oCurl->Error());
     }
     $oCurl->close();
     return json_decode($sResult);
 }
开发者ID:lunavod,项目名称:bunker_stable,代码行数:37,代码来源:Vk.class.php

示例14: fAlamat

function fAlamat($lat = 0, $lon = 0)
{
    include_once './curl.class.php';
    $curl = new Curl();
    //	$a = $curl->post('http://ws.geonames.org/extendedFindNearby?lng='.$lon.'&lat='.$lat);
    $a = $curl->post('http://maps.google.com/maps/geo?q=' . $lat . ',' . $lon . '&gl=id&output=xml');
    /*	
    	$r["negara"] 	= $a["geonames"]["geoname"][2]["name"];
    	$r["propinsi"] 	= $a["geonames"]["geoname"][3]["name"];
    	$r["kota"]		= $a["geonames"]["geoname"][4]["name"];
    */
    $r["koordinat"] = $a['kml']['Response']['name'];
    $r["alamat"] = $a['kml']['Response']['Placemark']['address'];
    $r["negara"] = $a['kml']['Response']['Placemark']['AddressDetails']['Country']['CountryName'];
    $r["propinsi"] = $a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['AdministrativeAreaName'];
    //if (empty($a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['SubAdministrativeAreaName'])){
    $r["kota"] = $a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['LocalityName'];
    $r["daerah"] = $a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocalityName'];
    $r["jalan"] = $a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['Thoroughfare']['ThoroughfareName'];
    //} else {
    //	$r["kota"]			= $a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['LocalityName'] . "," . $a['kml']['Response']['Placemark'][0]['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['SubAdministrativeAreaName'];
    //	$r["daerah"]		= $a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocality']['DependentLocalityName'];
    //	$r["jalan"]			= $a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocality']['Thoroughfare']['ThoroughfareName'];
    //}
    return $r;
}
开发者ID:nurulimamnotes,项目名称:Web-Tracking,代码行数:26,代码来源:inc.functions.php

示例15: webservice_post

function webservice_post($url, $params, $jsonRequest = FALSE)
{
    // Parse the RequestMethod out of the request for debugging purposes
    if (isset($params['RequestMethod'])) {
        $requestMethod = $params['RequestMethod'];
    } else {
        $requestMethod = '';
    }
    if (empty($url)) {
        log_message('error', "Canceling {$requestMethod} POST to an empty URL");
        return array('Message' => 'Web service URL is not configured');
    }
    if ($jsonRequest) {
        $params = json_encode($params);
    }
    // POST our query and fetch the response
    $curl = new Curl();
    $response = $curl->simple_post($url, $params);
    //log_message('debug', sprintf('Response received from %s POST to %s: %s', $requestMethod, $url, $response));
    // JSON decode the response
    $response = json_decode($response, TRUE);
    if (!isset($response)) {
        $response = array('Message' => 'Invalid or missing response');
    }
    return $response;
}
开发者ID:ronfesta,项目名称:simiangrid,代码行数:26,代码来源:index.php


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