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


PHP stream_context_set_default函数代码示例

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


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

示例1: server_http_headers

function server_http_headers($host, $ip, $port)
{
    global $timeout;
    // first check if server is http. otherwise long timeout.
    $ch = curl_init("https://" . $ip . ":" . $port);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: {$host}"));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FAILONERROR, true);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
    if (curl_exec($ch) === false) {
        curl_close($ch);
        return false;
    }
    curl_close($ch);
    stream_context_set_default(array("ssl" => array("verify_peer" => false, "capture_session_meta" => true, "verify_peer_name" => false, "peer_name" => $host, "allow_self_signed" => true, "sni_enabled" => true), 'http' => array('method' => 'GET', 'max_redirects' => 1, 'header' => 'Host: ' . $host, 'timeout' => $timeout)));
    $headers = get_headers("https://{$ip}:{$port}", 1);
    if (!empty($headers)) {
        $headers = array_change_key_case($headers, CASE_LOWER);
        return $headers;
    }
}
开发者ID:jackzh8,项目名称:ssl-decoder,代码行数:26,代码来源:connection.php

示例2: applyInitPathHook

 public static function applyInitPathHook($url, $context = 'core')
 {
     $params = [];
     $parts = AJXP_Utils::safeParseUrl($url);
     if (!($params = self::getLocalParams(self::CACHE_KEY . $url))) {
         // Nothing in cache
         $repositoryId = $parts["host"];
         $repository = ConfService::getRepositoryById($parts["host"]);
         if ($repository == null) {
             throw new \Exception("Cannot find repository");
         }
         $configHost = $repository->getOption('HOST');
         $configPath = $repository->getOption('PATH');
         $params['path'] = $parts['path'];
         $params['basepath'] = $configPath;
         $params['itemname'] = basename($params['path']);
         // Special case for root dir
         if (empty($params['path']) || $params['path'] == '/') {
             $params['path'] = '/';
         }
         $params['path'] = dirname($params['path']);
         $params['fullpath'] = rtrim($params['path'], '/') . '/' . $params['itemname'];
         $params['base_url'] = $configHost;
         $params['keybase'] = $repositoryId . $params['fullpath'];
         $params['key'] = md5($params['keybase']);
         self::addLocalParams(self::CACHE_KEY . $url, $params);
     }
     $repoData = self::actualRepositoryWrapperData($parts["host"]);
     $repoProtocol = $repoData['protocol'];
     $default = stream_context_get_options(stream_context_get_default());
     $default[$repoProtocol]['path'] = $params;
     $default[$repoProtocol]['client']->setDefaultUrl($configHost);
     stream_context_set_default($default);
 }
开发者ID:Nanomani,项目名称:pydio-core,代码行数:34,代码来源:PathWrapper.php

示例3: client_pydioAuth

/**
 * Pydio authentication
 *
 * @param  int $userId ftp username
 * @return bool FALSE on failure
 */
function client_pydioAuth($userId)
{
    if (file_exists(GUI_ROOT_DIR . '/data/tmp/failedAJXP.log')) {
        @unlink(GUI_ROOT_DIR . '/data/tmp/failedAJXP.log');
    }
    $credentials = _client_pydioGetLoginCredentials($userId);
    if (!$credentials) {
        set_page_message(tr('Unknown FTP user.'), 'error');
        return false;
    }
    $contextOptions = array();
    // Prepares Pydio absolute Uri to use
    if (isSecureRequest()) {
        $contextOptions = array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true));
    }
    $pydioBaseUrl = getBaseUrl() . '/ftp/';
    $port = getUriPort();
    // Pydio authentication
    $context = stream_context_create(array_merge($contextOptions, array('http' => array('method' => 'GET', 'protocol_version' => '1.1', 'header' => array('Host: ' . $_SERVER['SERVER_NAME'] . ($port ? ':' . $port : ''), 'User-Agent: i-MSCP', 'Connection: close')))));
    # Getting secure token
    $secureToken = file_get_contents("{$pydioBaseUrl}/index.php?action=get_secure_token", false, $context);
    $postData = http_build_query(array('get_action' => 'login', 'userid' => $credentials[0], 'login_seed' => '-1', "remember_me" => 'false', 'password' => stripcslashes($credentials[1]), '_method' => 'put'));
    $contextOptions = array_merge($contextOptions, array('http' => array('method' => 'POST', 'protocol_version' => '1.1', 'header' => array('Host: ' . $_SERVER['SERVER_NAME'] . ($port ? ':' . $port : ''), 'Content-Type: application/x-www-form-urlencoded', 'X-Requested-With: XMLHttpRequest', 'Content-Length: ' . strlen($postData), 'User-Agent: i-MSCP', 'Connection: close'), 'content' => $postData)));
    stream_context_set_default($contextOptions);
    # TODO Parse the full response and display error message on authentication failure
    $headers = get_headers("{$pydioBaseUrl}?secure_token={$secureToken}", true);
    _client_pydioCreateCookies($headers['Set-Cookie']);
    redirectTo($pydioBaseUrl);
    exit;
}
开发者ID:svenjantzen,项目名称:imscp,代码行数:36,代码来源:ftp_auth.php

示例4: updateRegistry

 public static function updateRegistry()
 {
     // WPN-XM Software Registry - Latest Version @ GitHub
     $url = 'https://raw.githubusercontent.com/WPN-XM/registry/master/wpnxm-software-registry.php';
     // fetch date header (doing a simple HEAD request)
     stream_context_set_default(array('http' => array('method' => 'HEAD')));
     // silenced: throws warning, if offline
     $headers = @get_headers($url, 1);
     // we are offline
     if (empty($headers) === true) {
         return false;
     }
     $file = WPNXM_DATA_DIR . 'wpnxm-software-registry.php';
     // parse header date
     $date = \DateTime::createFromFormat('D, d M Y H:i:s O', $headers['Date']);
     $last_modified = filemtime($file);
     // update condition, older than 1 week
     $needsUpdate = $date->getTimestamp() >= $last_modified + 7 * 24 * 60 * 60;
     // do update
     $updated = false;
     if ($needsUpdate === true) {
         // set request method back to GET, to fetch the file
         stream_context_set_default(array('http' => array('method' => 'GET')));
         $updated = file_put_contents($file, file_get_contents($url));
     }
     return $updated;
 }
开发者ID:siltronicz,项目名称:webinterface,代码行数:27,代码来源:Updater.php

示例5: get_http_response

/**
 * GET an HTTP URL to retrieve its content
 *
 * @param string $url      URL to get (http://...)
 * @param int    $timeout  network timeout (in seconds)
 * @param int    $maxBytes maximum downloaded bytes (default: 4 MiB)
 *
 * @return array HTTP response headers, downloaded content
 *
 * Output format:
 *  [0] = associative array containing HTTP response headers
 *  [1] = URL content (downloaded data)
 *
 * Example:
 *  list($headers, $data) = get_http_response('http://sebauvage.net/');
 *  if (strpos($headers[0], '200 OK') !== false) {
 *      echo 'Data type: '.htmlspecialchars($headers['Content-Type']);
 *  } else {
 *      echo 'There was an error: '.htmlspecialchars($headers[0]);
 *  }
 *
 * @see http://php.net/manual/en/function.file-get-contents.php
 * @see http://php.net/manual/en/function.stream-context-create.php
 * @see http://php.net/manual/en/function.get-headers.php
 */
function get_http_response($url, $timeout = 30, $maxBytes = 4194304)
{
    $urlObj = new Url($url);
    $cleanUrl = $urlObj->idnToAscii();
    if (!filter_var($cleanUrl, FILTER_VALIDATE_URL) || !$urlObj->isHttp()) {
        return array(array(0 => 'Invalid HTTP Url'), false);
    }
    $options = array('http' => array('method' => 'GET', 'timeout' => $timeout, 'user_agent' => 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:45.0)' . ' Gecko/20100101 Firefox/45.0', 'accept_language' => substr(setlocale(LC_COLLATE, 0), 0, 2) . ',en-US;q=0.7,en;q=0.3'));
    stream_context_set_default($options);
    list($headers, $finalUrl) = get_redirected_headers($cleanUrl);
    if (!$headers || strpos($headers[0], '200 OK') === false) {
        $options['http']['request_fulluri'] = true;
        stream_context_set_default($options);
        list($headers, $finalUrl) = get_redirected_headers($cleanUrl);
    }
    if (!$headers || strpos($headers[0], '200 OK') === false) {
        return array($headers, false);
    }
    try {
        // TODO: catch Exception in calling code (thumbnailer)
        $context = stream_context_create($options);
        $content = file_get_contents($finalUrl, false, $context, -1, $maxBytes);
    } catch (Exception $exc) {
        return array(array(0 => 'HTTP Error'), $exc->getMessage());
    }
    return array($headers, $content);
}
开发者ID:toneiv,项目名称:Shaarli,代码行数:52,代码来源:HttpUtils.php

示例6: github

function github($format)
{
    // location of cached file
    $file = 'assets/cache/contributors.json';
    // whatever this does, but it works
    stream_context_set_default(array("http" => array("header" => "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9")));
    // update cached file if it's older than half a day
    if (time() - filemtime($file) > 3600 * 12) {
        // || $_GET['forcerefresh']) {
        // get most recent json data
        $url = 'https://api.github.com/repos/thm/uinames/contributors?per_page=100';
        // check status
        if (getStatus($url) == 200) {
            // update cached file
            $data = file_get_contents($url);
            file_put_contents($file, $data, LOCK_EX);
        } else {
            $data = file_get_contents($file);
        }
        // prepare fresh data for implementation
        $data = json_decode($data, true);
    } else {
        // prepare cached data for implementation
        $data = json_decode(file_get_contents($file), true);
    }
    // shuffle people up so they're in a different spot every time
    shuffle($data);
    // loop: render faces
    for ($i = 0; $i < count($data); $i++) {
        $needles = ['$href', '$img', '$user', '$contributions'];
        $details = [$data[$i]['html_url'], $data[$i]['avatar_url'], $data[$i]['login'], $data[$i]['contributions']];
        echo str_replace($needles, $details, $format);
    }
}
开发者ID:AlbertoOlla,项目名称:uinames,代码行数:34,代码来源:dependables.php

示例7: getMp3StreamTitle

function getMp3StreamTitle($steam_url)
{
    $result = false;
    $icy_metaint = -1;
    $needle = 'StreamTitle=';
    $ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36';
    $opts = array('http' => array('method' => 'GET', 'header' => 'Icy-MetaData: 1', 'user_agent' => $ua));
    $default = stream_context_set_default($opts);
    $stream = fopen($steam_url, 'r');
    if ($stream && ($meta_data = stream_get_meta_data($stream)) && isset($meta_data['wrapper_data'])) {
        foreach ($meta_data['wrapper_data'] as $header) {
            if (strpos(strtolower($header), 'icy-metaint') !== false) {
                $tmp = explode(":", $header);
                $icy_metaint = trim($tmp[1]);
                break;
            }
        }
    }
    if ($icy_metaint != -1) {
        $buffer = stream_get_contents($stream, 300, $icy_metaint);
        if (strpos($buffer, $needle) !== false) {
            $title = explode($needle, $buffer);
            $title = trim($title[1]);
            $result = substr($title, 1, strpos($title, ';') - 2);
        }
    }
    if ($stream) {
        fclose($stream);
    }
    return $result;
}
开发者ID:yoelrola,项目名称:test-metadata-players,代码行数:31,代码来源:get.php

示例8: jsonrequest

function jsonrequest($url, $ip = NULL)
{
    $iptouse = is_null($ip) ? randomip() : $ip;
    $opts = array('socket' => array('bindto' => $iptouse . ':' . rand(49152, 65534)));
    stream_context_set_default($opts);
    $result = file_get_contents($url);
    return json_decode($result);
}
开发者ID:mikesee,项目名称:iplogger,代码行数:8,代码来源:get_geos.php

示例9: testContainerIsReturnedFromContext

 public function testContainerIsReturnedFromContext()
 {
     stream_context_set_default(array('contextContainerTest' => array('Container' => 'test')));
     $c = new Wrapper();
     $this->assertEquals('test', $c->getContainerFromContext('contextContainerTest://file'));
     $this->assertEquals('test', $c->getContainerFromContext('contextContainerTest://'));
     $this->assertEquals('test', $c->getContainerFromContext('contextContainerTest:///file'));
 }
开发者ID:mathroc,项目名称:php-vfs,代码行数:8,代码来源:WrapperTest.php

示例10: exists

 /**
  * {@inheritDoc}
  */
 public function exists()
 {
     // temporarily set context to use head request
     stream_context_set_default(['http' => ['method' => 'HEAD']]);
     $headers = get_headers($this->getUrl(), 1);
     // set context method back to get
     stream_context_set_default(['http' => ['method' => 'GET']]);
     return stristr($headers[0], '200');
 }
开发者ID:mindgruve,项目名称:derby,代码行数:12,代码来源:ReadOnlyRemoteFile.php

示例11: __construct

 /**
  * @param string $prefix
  */
 public function __construct(S3Client $client)
 {
     $protocol = 'dspace';
     $this->client = $client;
     $default = stream_context_get_options(stream_context_get_default());
     $default[$protocol]['client'] = $client;
     if (!isset($default[$protocol]['cache'])) {
         // Set a default cache adapter.
         $default[$protocol]['cache'] = new LruArrayCache();
     }
     stream_context_set_default($default);
 }
开发者ID:dspacelabs,项目名称:filesystem,代码行数:15,代码来源:AmazonS3Adapter.php

示例12: http_status

 /**
  * Get response code for REST API
  * - get_headers seems to be faster than wp_remote_request
  * - however, get_headers has no timeout
  * - seeing false positives from some servers
  * @param $url
  * @param $method
  * @return bool|int
  */
 private function http_status($url, $method = 'GET')
 {
     // try get_headers first
     stream_context_set_default(array('http' => array('method' => $method)));
     $headers = get_headers($url);
     if (isset($headers[0])) {
         return substr($headers[0], 9, 3) === '200';
     }
     // if get_headers fails, try wp_remote_request
     $args = array('method' => $method);
     $response = wp_remote_request($url, $args);
     return wp_remote_retrieve_response_code($response) === 200;
 }
开发者ID:bostondv,项目名称:WooCommerce-POS,代码行数:22,代码来源:class-wc-pos-status.php

示例13: testDefaultContextOptionsAreRemoved

 public function testDefaultContextOptionsAreRemoved()
 {
     return;
     $this->markTestSkipped('Skipped until I find a way to remove eys from default context options');
     stream_context_set_default(array('someContext' => array('a' => 'b')));
     $fs = new FileSystem();
     $scheme = $fs->scheme();
     unset($fs);
     //provoking __destruct
     $options = stream_context_get_options(stream_context_get_default());
     $this->assertArrayNotHasKey($scheme, $options, 'FS Context option present');
     $this->assertArrayHasKey('someContext', $options, 'Previously existing context option present');
 }
开发者ID:mathroc,项目名称:php-vfs,代码行数:13,代码来源:VirtualFilesystemTest.php

示例14: setInformation

 public function setInformation()
 {
     //Reasoning: faster, returns full headers
     // useful for obtaining metadata without response body
     //Warning: Some servers do not allow HTTP Head requests
     stream_context_set_default(array('http' => array('method' => 'HEAD')));
     $this->information = get_headers($this->getLocation(), 1);
     //We  need to download webpage data later on so change back to default
     stream_context_set_default(array('http' => array('method' => 'GET')));
     if ($this->getInformation() === false) {
         throw new \Exception("Either url does not exist or not url, or server disabled HEAD Requests");
     }
 }
开发者ID:gpcrocker,项目名称:ZendDirectoryInfo,代码行数:13,代码来源:URL.php

示例15: get_etag

 /**
  * Fetch ETag.
  *
  * @return string ETag or false.
  */
 public function get_etag()
 {
     if ($this->user != null && $this->pass != null) {
         stream_context_set_default(array('http' => array('header' => "Authorization: Basic " . base64_encode("{$this->user}:{$this->pass}") . "\r\n" . "User-Agent: PHP/" . PHP_VERSION)));
     }
     $headers = get_headers($this->url, 1);
     foreach ($headers as $key => $val) {
         $headers[strtolower($key)] = $val;
     }
     if (isset($headers['etag'])) {
         return str_replace(array("'", '"'), '', $headers['etag']);
     }
     return false;
 }
开发者ID:MetallianFR68,项目名称:myroundcube,代码行数:19,代码来源:ical_sync.php


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