本文整理汇总了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;
}
示例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.");
}
}
示例3: getIp
public static function getIp()
{
$co = new Curl(self::$ifconfigIp);
$co->setopt(CURLOPT_RETURNTRANSFER, true);
$ip = $co->exec();
return $ip;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例8: testValidatedSsl
function testValidatedSsl()
{
$curl = new Curl();
$curl->setValidateSsl(true);
$response = $curl->get('https://www.facebook.com/');
$this->assertEquals(200, $response->headers['Status-Code']);
}
示例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);
}
}
示例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;
}
}
示例11: test_error
function test_error()
{
assert_throws('CurlException', function () {
$curl = new Curl();
$curl->get('diaewkaksdljf-invalid-url-dot-com.com');
});
}
示例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();
}
}
示例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);
}
示例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;
}
示例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;
}