本文整理汇总了PHP中curl_close函数的典型用法代码示例。如果您正苦于以下问题:PHP curl_close函数的具体用法?PHP curl_close怎么用?PHP curl_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curl_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: query
function query($type)
{
if (!is_null($type)) {
//get parameter data
$parameters = Flight::request()->query->getData();
$cacheKey = $type . json_encode($parameters);
if (apc_exists($cacheKey)) {
echo apc_fetch($cacheKey);
} else {
$url = 'http://localhost:8080/sparql';
$query_string = file_get_contents('queries/' . $type . '.txt');
foreach ($parameters as $key => $value) {
$query_string = str_replace('{' . $key . '}', $value, $query_string);
}
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/sparql-query"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
apc_store($cacheKey, $result);
echo $result;
}
}
}
示例4: fetch
/**
* @param $url
* @param $destination
* @return bool|null
*/
public function fetch($url, $destination)
{
try {
$ret = null;
$url = $this->addhttp($url);
$ch = curl_init($url . '/favicon.ico');
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$contents = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode == 200) {
$fp = fopen($destination, 'w+');
fwrite($fp, $contents);
fclose($fp);
$ret = true;
if ($this->converter) {
$ret = $this->converter->convert($destination);
}
}
curl_close($ch);
return $ret;
} catch (\Exception $e) {
// hmm ok, let the next Fetcher try its luck
}
return null;
}
示例5: process
public function process($args)
{
$this->output = "";
if (strlen(trim($args)) > 0) {
try {
$url = "https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&maxResults=3&type=video&q=" . urlencode($args) . "&key=" . $this->apikey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$respuesta = curl_exec($ch);
curl_close($ch);
$resultados = json_decode($respuesta);
if (isset($resultados->error)) {
$this->output = "Ocurrió un problema al realizar la busqueda: " . $resultados->error->errors[0]->reason;
} else {
if (count($resultados->items) > 0) {
$videos = array();
foreach ($resultados->items as $video) {
array_push($videos, "http://www.youtube.com/watch?v=" . $video->id->videoId . " - " . $video->snippet->title);
}
$this->output = join("\n", $videos);
} else {
$this->output = "No se pudieron obtener resultados al realizar la busqueda indicada.";
}
}
} catch (Exception $e) {
$this->output = "Ocurrió un problema al realizar la busqueda: " . $e->getMessage();
}
} else {
$this->output = "Digame que buscar que no soy adivino.";
}
}
示例6: pdt
public function pdt($txn)
{
$params = array('at' => $this->atPaypal, 'tx' => $txn, 'cmd' => '_notify-synch');
$content = '';
foreach ($params as $key => $val) {
$content .= '&' . $key . '=' . urlencode($val);
}
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $this->paypalEndpoint);
curl_setopt($c, CURLOPT_VERBOSE, TRUE);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $content);
$response = curl_exec($c);
if (!$response) {
echo "FAILED: " . curl_error($c) . "(" . curl_errno($c) . ")";
curl_close($c);
return false;
} else {
$str = urldecode($response);
$res = explode("\n", strip_tags($str));
$result = array();
foreach ($res as $val) {
$r = explode("=", $val);
if (count($r) > 1) {
$result[$r[0]] = $r[1];
}
}
curl_close($c);
return $result;
}
}
示例7: jws_fetchUrl
function jws_fetchUrl($url)
{
//Can we use cURL?
if (is_callable('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$feedData = curl_exec($ch);
curl_close($ch);
//If not then use file_get_contents
} elseif (ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') === TRUE) {
$feedData = @file_get_contents($url);
//Or else use the WP HTTP API
} else {
if (!class_exists('WP_Http')) {
include_once ABSPATH . WPINC . '/class-http.php';
}
$request = new WP_Http();
$result = $request->request($url);
$feedData = $result['body'];
}
/* echo $feedData;
exit;*/
return $feedData;
}
示例8: 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));
}
示例9: exec
public function exec()
{
$active = null;
do {
do {
$status = curl_multi_exec($this->curlHandle, $active);
} while ($status == CURLM_CALL_MULTI_PERFORM);
if ($status != CURLM_OK) {
break;
}
$response = array();
$respond = curl_multi_info_read($this->curlHandle);
while ($respond) {
$callback = $this->requestMap[(string) $respond['handle']];
$responses[$callback]['content'] = curl_multi_getcontent($respond['handle']);
$responses[$callback]['httpcode'] = curl_getinfo($respond['handle'], CURLINFO_HTTP_CODE);
curl_multi_remove_handle($this->curlHandle, $respond['handle']);
curl_close($respond['handle']);
$respond = curl_multi_info_read($this->curlHandle);
}
if ($active > 0) {
curl_multi_select($this->curlHandle, 0.05);
}
} while ($active);
return $responses;
}
示例10: remote
/**
* Returns the output of a remote URL. Any [curl option](http://php.net/curl_setopt)
* may be used.
*
* // Do a simple GET request
* $data = Remote::get($url);
*
* // Do a POST request
* $data = Remote::get($url, array(
* CURLOPT_POST => TRUE,
* CURLOPT_POSTFIELDS => http_build_query($array),
* ));
*
* @param string remote URL
* @param array curl options
* @return string
* @throws Kohana_Exception
*/
public static function remote($url, array $options = NULL)
{
// The transfer must always be returned
$options[CURLOPT_RETURNTRANSFER] = TRUE;
// Open a new remote connection
$remote = curl_init($url);
// Set connection options
if (!curl_setopt_array($remote, $options)) {
throw new Kohana_Exception('Failed to set CURL options, check CURL documentation: :url', array(':url' => 'http://php.net/curl_setopt_array'));
}
// Get the response
$response = curl_exec($remote);
// Get the response information
$code = curl_getinfo($remote, CURLINFO_HTTP_CODE);
if ($code and $code < 200 or $code > 299) {
$error = $response;
} elseif ($response === FALSE) {
$error = curl_error($remote);
}
// Close the connection
curl_close($remote);
if (isset($error)) {
throw new Kohana_OAuth_Exception('Error fetching remote :url [ status :code ] :error', array(':url' => $url, ':code' => $code, ':error' => $error));
}
return $response;
}
示例11: httpRequest
public static function httpRequest($req, $hash_config = NULL)
{
$config = Obj2xml::getConfig($hash_config);
if ((int) $config['print_xml']) {
echo $req;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_PROXY, $config['proxy']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $config['timeout']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_SSLVERSION, 3);
$output = curl_exec($ch);
//$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (!$output) {
throw new \Exception(curl_error($ch));
} else {
curl_close($ch);
if ((int) $config['print_xml']) {
echo $output;
}
return $output;
}
}
示例12: downloadPackage
function downloadPackage($src, $dst)
{
if (ini_get('allow_url_fopen')) {
$file = @file_get_contents($src);
} else {
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $src);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 180);
$safeMode = @ini_get('safe_mode');
$openBasedir = @ini_get('open_basedir');
if (empty($safeMode) && empty($openBasedir)) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
}
$file = curl_exec($ch);
curl_close($ch);
} else {
return false;
}
}
file_put_contents($dst, $file);
return file_exists($dst);
}
示例13: wpc_curl_download
function wpc_curl_download($url)
{
// is cURL installed yet?
if (!function_exists('curl_init')) {
die('Sorry cURL is not installed!');
}
// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $url);
// Set a referer
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['SERVER_NAME']);
// User agent
curl_setopt($ch, CURLOPT_USERAGENT, 'MozillaXYZ/1.0');
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
return $output;
}
开发者ID:joffcrabtree,项目名称:wp-client-client-portals-file-upload-invoices-billing,代码行数:27,代码来源:wp-client-lite.php
示例14: test_instam
function test_instam($key)
{
// returns array, or FALSE
// snap(basename(__FILE__) . __LINE__, $key_val);
// http://www.instamapper.com/api?action=getPositions&key=4899336036773934943
$url = "http://www.instamapper.com/api?action=getPositions&key={$key}";
$data = "";
if (function_exists("curl_init")) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
} else {
// not CURL
if ($fp = @fopen($url, "r")) {
while (!feof($fp) && strlen($data) < 9000) {
$data .= fgets($fp, 128);
}
fclose($fp);
} else {
// print "-error 1"; // @fopen fails
return FALSE;
}
}
/*
InstaMapper API v1.00
1263013328977,bold,1236239763,34.07413,-118.34940,25.0,0.0,335
1088203381874,CABOLD,1236255869,34.07701,-118.35262,27.0,0.4,72
*/
// dump($data);
$ary_data = explode("\n", $data);
return $ary_data;
}
示例15: make_api_call
function make_api_call($url, $http_method, $post_data = array(), $uid = null, $key = null)
{
$full_url = 'https://app.onepagecrm.com/api/v3/' . $url;
$ch = curl_init($full_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $http_method);
$timestamp = time();
$auth_data = array($uid, $timestamp, $http_method, sha1($full_url));
$request_headers = array();
// For POST and PUT requests we will send data as JSON
// as with regular "form data" request we won't be able
// to send more complex structures
if ($http_method == 'POST' || $http_method == 'PUT') {
$request_headers[] = 'Content-Type: application/json';
$json_data = json_encode($post_data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$auth_data[] = sha1($json_data);
}
// Set auth headers if we are logged in
if ($key != null) {
$hash = hash_hmac('sha256', implode('.', $auth_data), $key);
$request_headers[] = "X-OnePageCRM-UID: {$uid}";
$request_headers[] = "X-OnePageCRM-TS: {$timestamp}";
$request_headers[] = "X-OnePageCRM-Auth: {$hash}";
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
$result = json_decode(curl_exec($ch));
curl_close($ch);
if ($result->status > 99) {
echo "API call error: {$result->message}\n";
return null;
}
return $result;
}