本文整理汇总了PHP中stream_context_set_default函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_context_set_default函数的具体用法?PHP stream_context_set_default怎么用?PHP stream_context_set_default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_context_set_default函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: register
/**
* Registers the dspace scheme
*/
protected function register()
{
if (in_array(self::PROTOCOL, stream_get_wrappers())) {
stream_wrapper_unregister(self::PROTOCOL);
}
stream_wrapper_register(self::PROTOCOL, '\\Dspacelabs\\Component\\Filesystem\\StreamWrapper', STREAM_IS_URL);
$default = stream_context_get_options(stream_context_get_default());
$default[self::PROTOCOL]['adapter'] = $this->adapter;
$default[self::PROTOCOL]['logger'] = $this->logger;
/**
* It might be worth putting a caching layer in
*/
//$default[self::PROTOCOL]['cache'] = $this->cache;
stream_context_set_default($default);
}
开发者ID:dspacelabs,项目名称:filesystem,代码行数:18,代码来源:Filesystem.php
示例17: testLink
/**
* Tests links for twitter/url
*/
protected function testLink($url)
{
stream_context_set_default(["http" => ["method" => "HEAD"]]);
try {
$headers = get_headers($url);
} catch (Exception $e) {
return false;
}
foreach ($headers as $header) {
if (stristr($header, "200 OK")) {
return $url;
}
}
return false;
}
开发者ID:gamerwalt,项目名称:laravelsnippets,代码行数:18,代码来源:Snippet.php
示例18: exists
/**
* Url Exists
*
* Tests whether or not a URL is legitimate by looking up the
* URL headers.
*
* Uses error silencing on get_headers(). PHP issues warning
* php_network_getaddresses: getaddrinfo on some invalid URL's
*
* @param string $url Url to lookup
* @return Returns TRUE if the URL exists or FALSE if not.
*/
public static function exists($url)
{
if (!UrlValidator::validate($url)) {
return false;
}
try {
// Change default stream context. get_headers uses GET by default.
stream_context_set_default(array('http' => array('method' => 'HEAD')));
$headers = @get_headers($url);
if (!$headers || preg_match('/404/', $headers[0]) === 1) {
return false;
}
} catch (Exception $e) {
return false;
}
return true;
}
开发者ID:rottingham,项目名称:urlvalidator,代码行数:29,代码来源:UrlValidator.class.php
示例19: __construct
public function __construct($environment = null, $debug = null)
{
// determine the environment / debug configuration based on whether or not this is running
// in App Engine's Dev App Server, or in production
if (is_null($debug)) {
$debug = !Environment::onAppEngine();
}
if (is_null($environment)) {
$environment = $debug ? 'dev' : 'prod';
}
parent::__construct($environment, $debug);
// Symfony console requires timezone to be set manually.
if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}
// Enable optimistic caching for GCS.
$options = ['gs' => ['enable_cache' => true, 'enable_optimistic_cache' => true, 'read_cache_expiry_seconds' => 300]];
stream_context_set_default($options);
$this->gcsBucketName = getenv('GCS_BUCKET_NAME');
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-symfony-starter-project,代码行数:20,代码来源:AppKernel.php
示例20: oldEggs
function oldEggs()
{
global $dbconn;
global $conf;
stream_context_set_default(array('http' => array('method' => 'HEAD', 'header' => "X-ApiKey: " . $conf["apikey"])));
$result = pg_query($dbconn, 'SELECT eggid, cosmid FROM eggs WHERE cosmid < 1000000');
if (!$result) {
die('SQL Error');
}
while ($row = pg_fetch_assoc($result)) {
$f = @get_headers("http://api.cosm.com/v2/feeds/" . urlencode($row['cosmid']));
if ($f[0] == "HTTP/1.1 404 Not Found") {
$query_params = array($row['eggid']);
if ($result = pg_query_params($dbconn, 'UPDATE eggs SET active = false WHERE eggid=$1', $query_params)) {
echo "Cosm id " . $row["cosmid"] . " was set inactive for being deleted<br>";
} else {
echo pg_last_error() . "<br>";
}
}
}
}
开发者ID:nvh3010,项目名称:eggtracker,代码行数:21,代码来源:query_eggs.php
注:本文中的stream_context_set_default函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论