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


PHP curl_exec函数代码示例

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


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

示例1: 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;
}
开发者ID:kousiksatish,项目名称:simple-gcm,代码行数:25,代码来源:internalgcmaccess.php

示例2: executeCurl

 private function executeCurl($url, array $params)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     if (isset($params["POST"])) {
         curl_setopt($ch, CURLOPT_POST, 1);
         $queryString = urlencode(http_build_query($params["POST"]));
         curl_setopt($ch, CURLOPT_POSTFIELDS, $queryString);
     }
     if (isset($params["PUT"])) {
         //@TODO
         throw new Exception('The PUT is currently not supported');
     }
     if (isset($params["GET"])) {
         curl_setopt($ch, CURLOPT_HTTPGET, 1);
         $queryString = urlencode(http_build_query($params["GET"]));
         curl_setopt($ch, CURLOPT_URL, $url . '?' . $queryString);
     }
     if (isset($params["HEADERS"])) {
         curl_setopt($ch, CURLOPT_HEADER, 1);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $params["HEADERS"]);
     }
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $response = curl_exec($ch);
     curl_close($ch);
     return $response;
 }
开发者ID:psosulski,项目名称:meta,代码行数:27,代码来源:ApiService.php

示例3: updateIndex

function updateIndex($lang, $file)
{
    $fileData = readFileData($file);
    $filename = $file->getPathName();
    list($filename) = explode('.', $filename);
    $path = $filename . '.html';
    $id = str_replace($lang . '/', '', $filename);
    $id = str_replace('/', '-', $id);
    $id = trim($id, '-');
    $url = implode('/', array(ES_URL, ES_INDEX, $lang, $id));
    $data = array('contents' => $fileData['contents'], 'title' => $fileData['title'], 'url' => $path);
    $data = json_encode($data);
    $size = strlen($data);
    $fh = fopen('php://memory', 'rw');
    fwrite($fh, $data);
    rewind($fh);
    echo "Sending request:\n\tfile: {$file}\n\turl: {$url}\n";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_PUT, true);
    curl_setopt($ch, CURLOPT_INFILE, $fh);
    curl_setopt($ch, CURLOPT_INFILESIZE, $size);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    $metadata = curl_getinfo($ch);
    if ($metadata['http_code'] > 400) {
        echo "[ERROR] Failed to complete request.\n";
        var_dump($response);
        exit(2);
    }
    curl_close($ch);
    fclose($fh);
    echo "Sent {$file}\n";
}
开发者ID:ramonakira,项目名称:docs,代码行数:33,代码来源:populate_search_index.php

示例4: updateCurrencies

 public function updateCurrencies()
 {
     if (extension_loaded('curl')) {
         $data = array();
         $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency WHERE code != '" . $this->db->escape($this->config->get('config_currency')) . "' AND date_modified > '" . date(strtotime('-1 day')) . "'");
         foreach ($query->rows as $result) {
             $data[] = $this->config->get('config_currency') . $result['code'] . '=X';
         }
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, 'http://download.finance.yahoo.com/d/quotes.csv?s=' . implode(',', $data) . '&f=sl1&e=.csv');
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $content = curl_exec($ch);
         curl_close($ch);
         $lines = explode("\n", trim($content));
         foreach ($lines as $line) {
             $currency = substr($line, 4, 3);
             $value = substr($line, 11, 6);
             if ((double) $value) {
                 $this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '" . (double) $value . "', date_modified = NOW() WHERE code = '" . $this->db->escape($currency) . "'");
             }
         }
         $this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '1.00000', date_modified = NOW() WHERE code = '" . $this->db->escape($this->config->get('config_currency')) . "'");
         $this->cache->delete('currency');
     }
 }
开发者ID:vverhun,项目名称:hoho,代码行数:25,代码来源:currency.php

示例5: 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));
 }
开发者ID:besimhu,项目名称:CraftCMS-Boilerplate,代码行数:27,代码来源:Github.php

示例6: processRequest

 public function processRequest($method = 'POST')
 {
     $params = http_build_query($this->urlParams);
     if (w2p_check_url($this->url)) {
         if (function_exists('curl_init')) {
             $ch = curl_init($this->url);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             $response = curl_exec($ch);
             curl_close($ch);
         } else {
             /*
              * Thanks to Wez Furlong for the core of the logic for this 
              *   method to POST data via PHP without cURL
              *   http://netevil.org/blog/2006/nov/http-post-from-php-without-curl
              */
             $ctx = stream_context_create($params);
             $fp = @fopen($this->url, 'rb', false, $ctx);
             if (!$fp) {
                 throw new Exception("Problem with {$url}, {$php_errormsg}");
             }
             $response = @stream_get_contents($fp);
             if ($response === false) {
                 throw new Exception("Problem reading data from {$url}, {$php_errormsg}");
             }
         }
         return $response;
     } else {
         //throw an error?
     }
 }
开发者ID:viniciusbudines,项目名称:sisnuss,代码行数:32,代码来源:HTTPRequest.class.php

示例7: GetRawResponse

 /**
  * Gets the raw response from the API for the provided uri as a string
  * @param string $uri 
  * @return string 
  */
 public function GetRawResponse($uri)
 {
     $ch = curl_init($uri);
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     return (string) curl_exec($ch);
 }
开发者ID:ContentLEAD,项目名称:BraftonJoomla3Component,代码行数:12,代码来源:AdferoHelpers.php

示例8: getTotalUsedCredits

 /**
  * @param $main_account_username
  * @param $main_account_password
  * @param $customer_username
  * @param DateTime $date
  * @return int
  * @throws Exception
  */
 public function getTotalUsedCredits($main_account_username, $main_account_password, $customer_username, DateTime $date)
 {
     $totalCreditUsed = 0;
     $this->customer = $customer_username;
     $this->date = $date;
     $this->main_account_username = $main_account_username;
     $this->main_account_password = $main_account_password;
     $this->date = $this->date->add(new DateInterval("P1D"));
     //the api call doesnt include the current date so we move a day ahead
     $dtToday = $this->date->format("Y-m-d");
     $requestString = "https://www.voipinfocenter.com/API/Request.ashx?command=calloverview&username={$this->main_account_username}&password={$this->main_account_password}&customer={$this->customer}&date={$dtToday}%2000:00:00&recordcount=500";
     $curlRes = curl_init($requestString);
     curl_setopt($curlRes, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curlRes, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($curlRes, CURLOPT_SSL_VERIFYHOST, false);
     $requestResult = curl_exec($curlRes);
     $this->date = $this->date->sub(new DateInterval("P1D"));
     //revert date add
     if (is_null($requestResult) || empty($requestResult)) {
         throw new Exception("Empty result from API server");
     }
     $xmlObject = new SimpleXMLElement($requestResult);
     $callsTempContainer = (array) $xmlObject->Calls;
     $callsTempContainer = $callsTempContainer['Call'];
     foreach ($callsTempContainer as $currentCallObj) {
         // if date is equal to date passed
         $parsedDate = strtotime($currentCallObj['StartTime']);
         if ($this->date->format("Y-m-d") === date("Y-m-d", $parsedDate)) {
             $totalCreditUsed += floatval($currentCallObj['Charge']);
         }
     }
     return $totalCreditUsed;
 }
开发者ID:branJakJak,项目名称:biOwAyPiTransperKreditz,代码行数:41,代码来源:CallOverview.php

示例9: request

 public function request($type, $url, array $params = array(), array $properties = array())
 {
     $params = array_filter($params);
     $ch = curl_init();
     switch (strtolower($type)) {
         case 'post':
             curl_setopt($ch, CURLOPT_POST, true);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
             break;
         case 'get':
             $url = $this->buildQueryString($url, $params);
             break;
         case 'delete':
             $url = $this->buildQueryString($url, $params);
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
             break;
         case 'update':
         case 'put':
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
             break;
     }
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_URL, $url);
     foreach ($properties as $propertyKey => $propertyValue) {
         curl_setopt($ch, $propertyKey, $propertyValue);
     }
     $response = curl_exec($ch);
     $info = curl_getinfo($ch);
     curl_close($ch);
     return new Response($info, $response);
 }
开发者ID:replay4me,项目名称:samba,代码行数:32,代码来源:APIBase.php

示例10: subscribe

function subscribe($apikey, $email, $dc, $list_id)
{
    $data = array('apikey' => $apikey, 'email_address' => $email, 'status' => 'subscribed');
    $json_data = json_encode($data);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://{$dc}.api.mailchimp.com/3.0/lists/{$list_id}/members/");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
    curl_setopt($ch, CURLOPT_USERPWD, "user:{$apikey}");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
    $result = json_decode(curl_exec($ch));
    if ($result->title == "Member Exists" || isset($result->id)) {
        ?>

		<h1>Thank you</h1>
		<a href="a.pdf" class="btn">Download File</a>
		<style>
		.btn{
			display: inline-block;
			padding: 10px;
			border: 1px solid #ccc;
			background-color: #efefef;
			text-decoration: none;
		}
		</style>

	<?php 
    }
}
开发者ID:withlovee,项目名称:mailchimp-api-subscription,代码行数:33,代码来源:mailchimp_submit.php

示例11: 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;
        }
    }
}
开发者ID:eugenesiow,项目名称:ldanalytics-PiSmartHome,代码行数:30,代码来源:query.php

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

示例13: 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);
 }
开发者ID:vgrish,项目名称:el,代码行数:25,代码来源:validate.install.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;
 }
开发者ID:sharedgeo,项目名称:TicketsCAD-SharedGeo-Dev,代码行数:34,代码来源:test_instam.php

示例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;
}
开发者ID:aprilla2crash,项目名称:shopify-tools,代码行数:34,代码来源:webhooks.php


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