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


PHP Util::handleContext方法代码示例

本文整理汇总了PHP中PMA\libraries\Util::handleContext方法的典型用法代码示例。如果您正苦于以下问题:PHP Util::handleContext方法的具体用法?PHP Util::handleContext怎么用?PHP Util::handleContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PMA\libraries\Util的用法示例。


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

示例1: getLatestVersion

 /**
  * Returns information with latest version from phpmyadmin.net
  *
  * @return object JSON decoded object with the data
  */
 public function getLatestVersion()
 {
     if (!$GLOBALS['cfg']['VersionCheck']) {
         return null;
     }
     // wait 3s at most for server response, it's enough to get information
     // from a working server
     $connection_timeout = 3;
     $response = '{}';
     // Get response text from phpmyadmin.net or from the session
     // Update cache every 6 hours
     if (isset($_SESSION['cache']['version_check']) && time() < $_SESSION['cache']['version_check']['timestamp'] + 3600 * 6) {
         $save = false;
         $response = $_SESSION['cache']['version_check']['response'];
     } else {
         $save = true;
         $file = 'https://www.phpmyadmin.net/home_page/version.json';
         if (ini_get('allow_url_fopen')) {
             $context = array('http' => array('request_fulluri' => true, 'timeout' => $connection_timeout));
             $context = Util::handleContext($context);
             if (!defined('TESTSUITE')) {
                 session_write_close();
             }
             $response = file_get_contents($file, false, stream_context_create($context));
         } else {
             if (function_exists('curl_init')) {
                 $curl_handle = curl_init($file);
                 if ($curl_handle === false) {
                     return null;
                 }
                 $curl_handle = Util::configureCurl($curl_handle);
                 curl_setopt($curl_handle, CURLOPT_HEADER, false);
                 curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
                 curl_setopt($curl_handle, CURLOPT_TIMEOUT, $connection_timeout);
                 if (!defined('TESTSUITE')) {
                     session_write_close();
                 }
                 $response = curl_exec($curl_handle);
             }
         }
     }
     /* Parse response */
     $data = json_decode($response);
     /* Basic sanity checking */
     if (!is_object($data) || empty($data->version) || empty($data->releases) || empty($data->date)) {
         return null;
     }
     if ($save) {
         if (!isset($_SESSION) && !defined('TESTSUITE')) {
             ini_set('session.use_only_cookies', 'false');
             ini_set('session.use_cookies', 'false');
             ini_set('session.use_trans_sid', 'false');
             ini_set('session.cache_limiter', 'nocache');
             session_start();
         }
         $_SESSION['cache']['version_check'] = array('response' => $response, 'timestamp' => time());
     }
     return $data;
 }
开发者ID:flash1452,项目名称:phpmyadmin,代码行数:64,代码来源:VersionInformation.php

示例2: httpRequestFopen

    /**
     * Creates HTTP request using file_get_contents
     *
     * @param string $url                Url to send the request
     * @param string $method             HTTP request method (GET, POST, PUT, DELETE, etc)
     * @param bool   $return_only_status If set to true, the method would only return response status
     * @param mixed  $content            Content to be sent with HTTP request
     * @param string $header             Header to be set for the HTTP request
     *
     * @return mixed
     */
    public static function httpRequestFopen($url, $method, $return_only_status = false, $content = null, $header = "")
    {
        $context = array(
            'http' => array(
                'method'  => $method,
                'request_fulluri' => true,
                'timeout' => 10,
                'user_agent' => 'phpMyAdmin',
                'header' => "Accept: */*",
            )
        );
        if ($header) {
            $context['http']['header'] .= "\n" . $header;
        }
        if ($method == "POST") {
            $context['http']['content'] = $content;
        }

        $context = Util::handleContext($context);
        $response = @file_get_contents(
            $url,
            false,
            stream_context_create($context)
        );
        if (! isset($http_response_header)) {
            return null;
        }
        preg_match("#HTTP/[0-9\.]+\s+([0-9]+)#", $http_response_header[0], $out );
        $http_status = intval($out[1]);
        return Util::httpRequestReturn($response, $http_status, $return_only_status);
    }
开发者ID:nijel,项目名称:phpmyadmin,代码行数:42,代码来源:Util.php


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