本文整理汇总了PHP中stream_context_set_params函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_context_set_params函数的具体用法?PHP stream_context_set_params怎么用?PHP stream_context_set_params使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_context_set_params函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: initialize
/**
* Initializes observr collections by aliasing
* stream_context_set_option and stream_context_set_params
*/
private function initialize()
{
$this->options->merge(\stream_context_get_options($this->context));
$this->options->attach('set', function ($sender, $e) {
\stream_context_set_option($this->context, $this->wrapper, $e->offset, $e->value);
});
$this->data->merge(\stream_context_get_params($this->context));
$this->data->attach('set', function ($sender, $e) {
\stream_context_set_params($this->context, $this->data->toArray());
});
}
开发者ID:jgswift,项目名称:qio,代码行数:15,代码来源:Context.php
示例2: loadDocument
/**
* Loads a remote document or context
*
* @param string $url The URL of the document to load.
*
* @return RemoteDocument The remote document.
*
* @throws JsonLdException If loading the document failed.
*/
public static function loadDocument($url)
{
// if input looks like a file, try to retrieve it
$input = trim($url);
if (false == (isset($input[0]) && "{" === $input[0] || "[" === $input[0])) {
$remoteDocument = new RemoteDocument($url);
$streamContextOptions = array('method' => 'GET', 'header' => "Accept: application/ld+json, application/json; q=0.9, */*; q=0.1\r\n", 'timeout' => Processor::REMOTE_TIMEOUT);
$context = stream_context_create(array('http' => $streamContextOptions, 'https' => $streamContextOptions));
$httpHeadersOffset = 0;
stream_context_set_params($context, array('notification' => function ($code, $severity, $msg, $msgCode, $bytesTx, $bytesMax) use(&$remoteDocument, &$http_response_header, &$httpHeadersOffset) {
if ($code === STREAM_NOTIFY_MIME_TYPE_IS) {
$remoteDocument->mediaType = $msg;
} elseif ($code === STREAM_NOTIFY_REDIRECTED) {
$remoteDocument->documentUrl = $msg;
$remoteDocument->mediaType = null;
$httpHeadersOffset = count($http_response_header);
}
}));
if (false === ($input = @file_get_contents($url, false, $context))) {
throw new JsonLdException(JsonLdException::LOADING_DOCUMENT_FAILED, sprintf('Unable to load the remote document "%s".', $url), $http_response_header);
}
// Extract HTTP Link headers
$linkHeaderValues = array();
for ($i = count($http_response_header) - 1; $i > $httpHeadersOffset; $i--) {
if (0 === substr_compare($http_response_header[$i], 'Link:', 0, 5, true)) {
$value = substr($http_response_header[$i], 5);
$linkHeaderValues[] = $value;
}
}
$linkHeaderValues = self::parseContextLinkHeaders($linkHeaderValues, new IRI($url));
if (count($linkHeaderValues) === 1) {
$remoteDocument->contextUrl = reset($linkHeaderValues);
} elseif (count($linkHeaderValues) > 1) {
throw new JsonLdException(JsonLdException::MULTIPLE_CONTEXT_LINK_HEADERS, 'Found multiple contexts in HTTP Link headers', $http_response_header);
}
// If we got a media type, we verify it
if ($remoteDocument->mediaType) {
// Drop any media type parameters such as profiles
if (false !== ($pos = strpos($remoteDocument->mediaType, ';'))) {
$remoteDocument->mediaType = substr($remoteDocument->mediaType, 0, $pos);
}
$remoteDocument->mediaType = trim($remoteDocument->mediaType);
if ('application/ld+json' === $remoteDocument->mediaType) {
$remoteDocument->contextUrl = null;
} elseif ('application/json' !== $remoteDocument->mediaType && 0 !== substr_compare($remoteDocument->mediaType, '+json', -5)) {
throw new JsonLdException(JsonLdException::LOADING_DOCUMENT_FAILED, 'Invalid media type', $remoteDocument->mediaType);
}
}
$remoteDocument->document = Processor::parse($input);
return $remoteDocument;
}
return new RemoteDocument($url, Processor::parse($input));
}
开发者ID:janul,项目名称:JsonLD,代码行数:62,代码来源:FileGetContentsLoader.php
示例3: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$current = $this->getApplication()->getVersion();
if (false === ($latest = @file_get_contents('http://kzykhys.com/coupe/version'))) {
$output->writeln('<error>Failed to connect to http://kzykhys.com/coupe/version</error>');
return 255;
}
if (!$input->getOption('force')) {
if ($current === $latest) {
$output->writeln('<info>You are using the latest version [' . $current . ']</info>');
return 0;
}
}
/* @var \Symfony\Component\Console\Helper\ProgressHelper $progress */
$progress = $this->getHelper('progress');
$fileSize = 0;
$currentPercent = 0;
$progress->start($output, 100);
$context = stream_context_create();
stream_context_set_params($context, ["notification" => function ($c, $s, $m, $mc, $transferred, $max) use(&$progress, &$fileSize, &$currentPercent) {
switch ($c) {
case STREAM_NOTIFY_FILE_SIZE_IS:
$fileSize = $max;
break;
case STREAM_NOTIFY_PROGRESS:
if ($transferred > 0) {
$percent = (int) ($transferred / $fileSize * 100);
$progress->advance($percent - $currentPercent);
$currentPercent = $percent;
}
break;
}
}]);
$output->writeln('Downloading <fg=green;options=bold>' . $latest . '</fg=green;options=bold> ...');
if (false === ($phar = @file_get_contents('http://kzykhys.com/coupe/coupe.phar', false, $context))) {
$output->writeln('<error>Failed to download new coupe version</error>');
return 255;
}
$progress->setCurrent(100);
$progress->finish();
$pharPath = $GLOBALS['argv'][0];
$fs = new Filesystem();
$fs->copy($pharPath, $backup = tempnam(sys_get_temp_dir(), 'coupe_phar_backup'));
if (false == @file_put_contents($pharPath, $phar)) {
$fs->remove($pharPath);
$fs->rename($backup, $pharPath);
$output->writeln('<error>Failed to update coupe to the latest version</error>');
return 1;
}
$fs->remove($backup);
return 0;
}
开发者ID:kzykhys,项目名称:coupe,代码行数:55,代码来源:SelfUpdateCommand.php
示例4: _hush_download
function _hush_download($down_file, $save_file)
{
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => "_hush_download_callback"));
$fp = fopen($down_file, "r", false, $ctx);
if (is_resource($fp) && file_put_contents($save_file, $fp)) {
echo "\nDone!\n";
return true;
}
$err = error_get_last();
echo "\nError.. ", $err["message"], "\n";
return false;
}
开发者ID:liningwang,项目名称:camera-beijing,代码行数:13,代码来源:global.funcs.php
示例5: createSocket
public function createSocket($recreate = false)
{
$flags = STREAM_CLIENT_ASYNC_CONNECT;
if (!$this->_socket || $recreate === true) {
if ($this->_socket = @stream_socket_client($this->protocol . "://" . $this->host . ':' . $this->port, $errno, $errstr, $this->timeout, $flags)) {
stream_set_blocking($this->_socket, false);
stream_context_set_params($this->_socket, array("notification" => array($this, 'stream_notification_callback')));
$this->_state_socket = true;
$this->_socket_error = array();
} else {
$this->_socket_error = array('error_num' => $errno, 'error_message' => $errstr);
}
}
}
开发者ID:stacksight,项目名称:stacksight-php-sdk,代码行数:14,代码来源:SSHttpRequestSockets.php
示例6: updates
/**
* @param string $version
* @return string
*/
public function updates($version = self::LATEST)
{
$tag = $version;
if (self::LATEST == $version) {
$tag = 'master';
}
if (ini_get('phar.readonly') == true) {
throw new \RuntimeException('Unable to update the PHAR, phar.readonly is set, use \'-d phar.readonly=0\'');
}
if (ini_get('allow_url_fopen') == false) {
throw new \RuntimeException('Unable to update the PHAR, allow_url_fopen is not set, use \'-d allow_url_fopen=1\'');
}
$currentPharLocation = \Phar::running(false);
if (!file_exists($currentPharLocation) || strlen($currentPharLocation) == 0) {
throw new \LogicException("You're not currently using Phar. If you have installed PhpMetrics with Composer, please updates it using Composer.");
}
if (!is_writable($currentPharLocation)) {
throw new \RuntimeException(sprintf('%s is not writable', $currentPharLocation));
}
// downloading
$url = sprintf($this->url, $tag);
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => array($this, 'stream_notification_callback')));
$content = file_get_contents($url, false, $ctx);
// replacing file
if (!$content) {
throw new \RuntimeException('Download failed');
}
// check if all is OK
$tmpfile = tempnam(sys_get_temp_dir(), 'phar');
file_put_contents($tmpfile, $content);
$output = shell_exec(sprintf('"%s" "%s" --version', PHP_BINARY, $tmpfile));
if (!preg_match('!(v\\d+\\.\\d+\\.\\d+)!', $output, $matches)) {
throw new \RuntimeException('Phar is corrupted. Please retry');
}
// compare versions
$downloadedVersion = $matches[1];
if (self::LATEST !== $version && $downloadedVersion !== $version) {
throw new \RuntimeException('Incorrect version. Please retry');
}
// at this step, all is ok
file_put_contents($currentPharLocation, $content);
return $version;
}
开发者ID:YuraLukashik,项目名称:PhpMetrics,代码行数:48,代码来源:Updater.php
示例7: run
public static function run($r)
{
foreach (pts_types::identifiers_to_test_profile_objects($r, true, true) as $test_profile) {
echo 'Checking: ' . $test_profile . PHP_EOL;
foreach (pts_test_install_request::read_download_object_list($test_profile) as $test_file_download) {
foreach ($test_file_download->get_download_url_array() as $url) {
$stream_context = pts_network::stream_context_create();
stream_context_set_params($stream_context, array('notification' => 'pts_stream_status_callback'));
$file_pointer = @fopen($url, 'r', false, $stream_context);
//fread($file_pointer, 1024);
if ($file_pointer == false) {
echo PHP_EOL . 'BAD URL: ' . $test_file_download->get_filename() . ' / ' . $url . PHP_EOL;
} else {
@fclose($file_pointer);
}
}
}
}
}
开发者ID:ShaolongHu,项目名称:phoronix-test-suite,代码行数:19,代码来源:debug_test_download_links.php
示例8: sendRequest
/**
* Send the request
*
* This function sends the actual request to the
* remote/local webserver using php streams.
*/
public function sendRequest()
{
$proxyurl = '';
$request_fulluri = false;
if (!is_null($this->proxy)) {
$proxyurl = $this->proxy->url;
$request_fulluri = true;
}
$info = array($this->uri->protocol => array('method' => $this->verb, 'content' => $this->body, 'header' => $this->buildHeaderString(), 'proxy' => $proxyurl, 'ignore_errors' => true, 'max_redirects' => 3, 'request_fulluri' => $request_fulluri));
// create context with proper junk
$ctx = stream_context_create($info);
if (count($this->_listeners)) {
stream_context_set_params($ctx, array('notification' => array($this, 'streamNotifyCallback')));
}
$fp = fopen($this->uri->url, 'rb', false, $ctx);
if (!is_resource($fp)) {
throw new Request\Exception('Url ' . $this->uri->url . ' could not be opened (PhpStream Adapter)');
} else {
restore_error_handler();
}
stream_set_timeout($fp, $this->requestTimeout);
$body = stream_get_contents($fp);
if ($body === false) {
throw new Request\Exception('Url ' . $this->uri->url . ' did not return a response');
}
$meta = stream_get_meta_data($fp);
fclose($fp);
$headers = $meta['wrapper_data'];
$details = $this->uri->toArray();
$tmp = $this->parseResponseCode($headers[0]);
$details['code'] = $tmp['code'];
$details['httpVersion'] = $tmp['httpVersion'];
$cookies = array();
$this->headers = $this->cookies = array();
foreach ($headers as $line) {
$this->processHeader($line);
}
return new Request\Response($details, $body, new Request\Headers($this->headers), $this->cookies);
}
开发者ID:peopleplan,项目名称:Pyrus,代码行数:45,代码来源:Phpstream.php
示例9: download
/**
* @param \FlickrDownloadr\Photo\Photo $photo
* @param string $filename
* @param string $dirname
* @return int Number of bytes that were written to the file, or FALSE on failure
*/
public function download(Photo $photo, $filename, $dirname)
{
$url = $photo->getUrl();
if ($this->dryRun) {
return 0;
}
\Nette\Utils\FileSystem::createDir($dirname . '/' . dirname($filename));
$this->setupProgressBar();
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => $this->getNotificationCallback($filename)));
$bytes = file_put_contents($dirname . '/' . $filename, fopen($url, 'r', FALSE, $ctx));
if ($bytes === FALSE) {
$this->progress->setMessage('<error>Error!</error>', 'final_report');
} else {
list($time, $size, $speed) = $this->getFinalStats($this->progress->getMaxSteps(), $this->progress->getStartTime());
$this->progress->setMessage('<comment>[' . $size . ' in ' . $time . ' (' . $speed . ')]</comment>', 'final_report');
$this->progress->setFormat('%message% %final_report%' . "\n");
}
$this->progress->finish();
$this->output->writeln('');
return $bytes;
}
开发者ID:michalsanger,项目名称:cli-flickr-downloadr,代码行数:28,代码来源:Downloader.php
示例10: download_file
/**
* Download a file ($url) to a given path ($savepath) and display progress information while doing it
* Optionally check saved file against a known md5 hash
*/
function download_file($url, $savepath, $md5hash = false)
{
// Stream the file, and output status information as defined in stream_notification_callback() via STREAM_NOTIFY_PROGRESS
// Requires PHP 5.2.0+
$ctx = stream_context_create();
stream_context_set_params($ctx, array('notification' => 'stream_notification_callback'));
$fp = fopen($url, 'r', false, $ctx);
if (!$fp) {
echo "ERROR: Unable to open this url for download: {$url}", PHP_EOL;
return false;
}
if (is_resource($fp) && file_put_contents($savepath, $fp)) {
fclose($fp);
if ($md5hash) {
if (md5_file($savepath) === $md5hash) {
return true;
} else {
return false;
}
}
return true;
}
return false;
}
开发者ID:philip,项目名称:PhpVersionBuilder,代码行数:28,代码来源:pvb-functions.php
示例11: sendRequest
/**
* Sends a PSR-7 request.
*
* @param RequestInterface $request
*
* @return ResponseInterface
*
* @throws \Http\Client\Exception If an error happens during processing the request.
* @throws \Exception If processing the request is impossible (eg. bad configuration).
*/
public function sendRequest(RequestInterface $request)
{
$body = (string) $request->getBody();
$headers = [];
foreach (array_keys($request->getHeaders()) as $headerName) {
if (strtolower($headerName) === 'content-length') {
$values = array(strlen($body));
} else {
$values = $request->getHeader($headerName);
}
foreach ($values as $value) {
$headers[] = $headerName . ': ' . $value;
}
}
$streamContextOptions = array('protocol_version' => $request->getProtocolVersion(), 'method' => $request->getMethod(), 'header' => implode("\r\n", $headers), 'timeout' => $this->timeout, 'ignore_errors' => true, 'follow_location' => $this->followRedirects ? 1 : 0, 'max_redirects' => 100);
if (strlen($body) > 0) {
$streamContextOptions['content'] = $body;
}
$context = stream_context_create(array('http' => $streamContextOptions, 'https' => $streamContextOptions));
$httpHeadersOffset = 0;
$finalUrl = (string) $request->getUri();
stream_context_set_params($context, array('notification' => function ($code, $severity, $msg, $msgCode, $bytesTx, $bytesMax) use(&$remoteDocument, &$http_response_header, &$httpHeadersOffset) {
if ($code === STREAM_NOTIFY_REDIRECTED) {
$finalUrl = $msg;
$httpHeadersOffset = count($http_response_header);
}
}));
$response = $this->messageFactory->createResponse();
if (false === ($responseBody = @file_get_contents((string) $request->getUri(), false, $context))) {
if (!isset($http_response_header)) {
throw new NetworkException('Unable to execute request', $request);
}
} else {
$response = $response->withBody($this->streamFactory->createStream($responseBody));
}
$parser = new HeaderParser();
try {
return $parser->parseArray(array_slice($http_response_header, $httpHeadersOffset), $response);
} catch (\Exception $e) {
throw new RequestException($e->getMessage(), $request, $e);
}
}
开发者ID:lanthaler,项目名称:fgc-client,代码行数:52,代码来源:FgcHttpClient.php
示例12: _build_context
public function _build_context($url, $params = '', $method = 'GET', $headers = '', $files = array())
{
$options = array();
$options['http']['header'] = array();
$options['http']['method'] = $method;
$options['http']['timeout'] = $this->client->timeout;
if ($this->client->bindip) {
$options['socket']['bindto'] = $this->client->bindip;
}
$context = $this->_init_context();
if (is_array($params)) {
$data = http_build_query($params);
} else {
$data = $params;
}
if (!empty($files)) {
$boundary = "---------------------" . substr(uniqid(), 0, 10);
$data = "--{$boundary}\r\n";
foreach ($params as $key => $val) {
$data .= "Content-Disposition: form-data; name=\"" . $key . "\"\r\n\r\n" . $val . "\r\n";
$data .= "--{$boundary}\r\n";
}
foreach ($files as $key => $file) {
$size = @getimagesize($file);
if (isset($size['mime'])) {
$mime = $size['mime'];
} else {
$mime = 'application/octet-stream';
}
$data .= "Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file}\"\r\n";
$data .= "Content-Type: {$mime}\r\n";
$data .= "Content-Transfer-Encoding: binary\r\n\r\n";
$data .= file_get_contents($file) . "\r\n";
$data .= "--{$boundary}\r\n";
}
}
if ($method == 'POST') {
if ($files) {
$options['http']['header'][] = "Content-Type: multipart/form-data; boundary={$boundary}\r\n";
} else {
$options['http']['header'][] = "Content-Type: application/x-www-form-urlencoded\r\n";
}
if ($data) {
$options['http']['content'] = $data;
}
} elseif ($method == 'GET') {
if ($params) {
$url .= '?' . $data;
}
}
if ($headers) {
if (is_array($headers)) {
$options['http']['header'] = array_merge($options['http']['header'], $headers);
} else {
$options['http']['header'][] = $headers;
}
if (!empty($this->client->headers)) {
$options['http']['header'] = array_merge($options['http']['header'], $this->client->headers);
}
}
if (!empty($this->client->cookie)) {
if (!is_scalar($this->client->cookie)) {
$cookie = http_build_query($this->client->cookie);
} else {
$cookie = $this->client->cookie;
}
$options['http']['header'][] = "Cookie: {$cookie}\r\n";
}
$options['http']['header'] = implode("\r\n", array_map('trim', $options['http']['header']));
$options['http']['ignore_errors'] = 1;
stream_context_set_params($context, $options);
return $context;
}
开发者ID:hemantshekhawat,项目名称:Snippets,代码行数:73,代码来源:VHTTP.php
示例13: validate_test_profile
public static function validate_test_profile(&$test_profile)
{
if ($test_profile->get_file_location() == null) {
echo PHP_EOL . 'ERROR: The file location of the XML test profile source could not be determined.' . PHP_EOL;
return false;
}
// Validate the XML against the XSD Schemas
libxml_clear_errors();
// Now re-create the pts_test_profile object around the rewritten XML
$test_profile = new pts_test_profile($test_profile->get_identifier());
$valid = $test_profile->validate();
if ($valid == false) {
echo PHP_EOL . 'Errors occurred parsing the main XML.' . PHP_EOL;
pts_validation::process_libxml_errors();
return false;
}
// Rewrite the main XML file to ensure it is properly formatted, elements are ordered according to the schema, etc...
$test_profile_writer = new pts_test_profile_writer();
$test_profile_writer->rebuild_test_profile($test_profile);
$test_profile_writer->save_xml($test_profile->get_file_location());
// Now re-create the pts_test_profile object around the rewritten XML
$test_profile = new pts_test_profile($test_profile->get_identifier());
$valid = $test_profile->validate();
if ($valid == false) {
echo PHP_EOL . 'Errors occurred parsing the main XML.' . PHP_EOL;
pts_validation::process_libxml_errors();
return false;
} else {
echo PHP_EOL . 'Test Profile XML Is Valid.' . PHP_EOL;
}
// Validate the downloads file
$download_xml_file = $test_profile->get_file_download_spec();
if (empty($download_xml_file) == false) {
$writer = new pts_test_profile_downloads_writer();
$writer->rebuild_download_file($test_profile);
$writer->save_xml($download_xml_file);
$downloads_parser = new pts_test_downloads_nye_XmlReader($download_xml_file);
$valid = $downloads_parser->validate();
if ($valid == false) {
echo PHP_EOL . 'Errors occurred parsing the downloads XML.' . PHP_EOL;
pts_validation::process_libxml_errors();
return false;
} else {
echo PHP_EOL . 'Test Downloads XML Is Valid.' . PHP_EOL;
}
// Validate the individual download files
echo PHP_EOL . 'Testing File Download URLs.' . PHP_EOL;
$files_missing = 0;
$file_count = 0;
foreach (pts_test_install_request::read_download_object_list($test_profile) as $download) {
foreach ($download->get_download_url_array() as $url) {
$stream_context = pts_network::stream_context_create();
stream_context_set_params($stream_context, array('notification' => 'pts_stream_status_callback'));
$file_pointer = fopen($url, 'r', false, $stream_context);
if ($file_pointer == false) {
echo 'File Missing: ' . $download->get_filename() . ' / ' . $url . PHP_EOL;
$files_missing++;
} else {
fclose($file_pointer);
}
$file_count++;
}
}
if ($files_missing > 0) {
return false;
}
}
// Validate the parser file
$parser_file = $test_profile->get_file_parser_spec();
if (empty($parser_file) == false) {
$writer = self::rebuild_result_parser_file($parser_file);
$writer->saveXMLFile($parser_file);
$parser = new pts_parse_results_nye_XmlReader($parser_file);
$valid = $parser->validate();
if ($valid == false) {
echo PHP_EOL . 'Errors occurred parsing the results parser XML.' . PHP_EOL;
pts_validation::process_libxml_errors();
return false;
} else {
echo PHP_EOL . 'Test Results Parser XML Is Valid.' . PHP_EOL;
}
}
// Make sure no extra files are in there
$allowed_files = pts_validation::test_profile_permitted_files();
foreach (pts_file_io::glob($test_profile->get_resource_dir() . '*') as $tp_file) {
if (!is_file($tp_file) || !in_array(basename($tp_file), $allowed_files)) {
echo PHP_EOL . basename($tp_file) . ' is not allowed in the test package.' . PHP_EOL;
return false;
}
}
return true;
}
开发者ID:ptzafrir,项目名称:phoronix-test-suite,代码行数:92,代码来源:pts_validation.php
示例14: stream_download
public static function stream_download($download, $download_to, $stream_context_parameters = null, $callback_function = array('pts_network', 'stream_status_callback'))
{
$stream_context = pts_network::stream_context_create($stream_context_parameters);
if (function_exists('stream_context_set_params')) {
// HHVM 2.1 doesn't have stream_context_set_params()
stream_context_set_params($stream_context, array('notification' => $callback_function));
}
/*
if(strpos($download, 'https://openbenchmarking.org/') !== false)
{
stream_context_set_option($stream_context, 'ssl', 'local_cert', PTS_CORE_STATIC_PATH . 'certificates/openbenchmarking-server.pem');
}
else if(strpos($download, 'https://www.phoromatic.com/') !== false)
{
stream_context_set_option($stream_context, 'ssl', 'local_cert', PTS_CORE_STATIC_PATH . 'certificates/phoromatic-com.pem');
}
*/
$file_pointer = @fopen($download, 'r', false, $stream_context);
if (is_resource($file_pointer) && file_put_contents($download_to, $file_pointer)) {
return true;
}
return false;
}
开发者ID:pchiruma,项目名称:phoronix-test-suite,代码行数:23,代码来源:pts_network.php
示例15: jsonld_default_secure_document_loader
/**
* The default implementation to retrieve JSON-LD at the given secure URL.
*
* @param string $url the secure URL to to retrieve.
*
* @return stdClass the RemoteDocument object.
*/
function jsonld_default_secure_document_loader($url)
{
if (strpos($url, 'https') !== 0) {
throw new Exception("Could not GET url: '{$url}'; 'https' is required.");
}
$redirects = array();
// default JSON-LD https GET implementation
$opts = array('https' => array('verify_peer' => true, 'method' => "GET", 'header' => "Accept: application/ld+json\r\n" . "User-Agent: JSON-LD PHP Client/1.0\r\n"));
$stream = stream_context_create($opts);
stream_context_set_params($stream, array('notification' => function ($notification_code, $severity, $message) use(&$redirects) {
switch ($notification_code) {
case STREAM_NOTIFY_REDIRECTED:
$redirects[] = $message;
break;
}
}));
$result = @file_get_contents($url, false, $stream);
if ($result === false) {
throw new Exception("Could not GET url: '{$url}'");
}
foreach ($redirects as $redirect) {
if (strpos($redirect, 'https') !== 0) {
throw new Exception("Could not GET redirected url: '{$redirect}'; 'https' is required.");
}
$url = $redirect;
}
// return RemoteDocument
return (object) array('contextUrl' => null, 'document' => $result, 'documentUrl' => $url);
}
开发者ID:sprklinginfo,项目名称:OACVideoAnnotator,代码行数:36,代码来源:jsonld.php
示例16: podlovewebplayer_render_chapters
function podlovewebplayer_render_chapters($input)
{
global $post;
if (json_decode($input) === null) {
$input = trim($input);
$chapters = false;
if ($input != '') {
if (substr($input, 0, 7) == 'http://' || substr($input, 0, 8) == 'https://') {
$http_context = stream_context_create();
stream_context_set_params($http_context, array('user_agent' => 'UserAgent/1.0'));
$chapters = trim(@file_get_contents($input, 0, $http_context));
$json_chapters = json_decode($chapters);
if ($json_chapters !== null) {
return $json_chapters;
}
} elseif ($chapters = get_post_custom_values($input, $post->ID)) {
$chapters = trim($chapters[0]);
$json_chapters = json_decode($chapters);
if ($json_chapters !== null) {
return $json_chapters;
}
}
}
if ($chapters == '') {
return '';
}
preg_match_all('/((\\d+:)?(\\d\\d?):(\\d\\d?)(?:\\.(\\d+))?) ([^<>\\r\\n]{3,}) ?(<([^<>\\r\\n]*)>\\s*(<([^<>\\r\\n]*)>\\s*)?)?\\r?/', $chapters, $chapterArrayTemp, PREG_SET_ORDER);
$chaptercount = count($chapterArrayTemp);
for ($i = 0; $i < $chaptercount; ++$i) {
$chapterArray[$i]['start'] = $chapterArrayTemp[$i][1];
$chapterArray[$i]['title'] = htmlspecialchars($chapterArrayTemp[$i][6], ENT_QUOTES);
if (isset($chapterArrayTemp[$i][9])) {
$chapterArray[$i]['image'] = trim($chapterArrayTemp[$i][10], '<> ()\'');
}
if (isset($chapterArrayTemp[$i][7])) {
$chapterArray[$i]['href'] = trim($chapterArrayTemp[$i][8], '<> ()\'');
}
}
return $chapterArray;
}
return $input;
}
开发者ID:johannes-mueller,项目名称:podlove-web-player,代码行数:42,代码来源:podlove-web-player.php
示例17: file_get_contents_with_console
function file_get_contents_with_console($filename)
{
consoleLog("Download: " . $filename);
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
$data = @file_get_contents($filename, false, $ctx);
if ($data !== false) {
$size = strlen($data);
consoleLogProgressBar($size, $size);
consoleLogBlank();
consoleLogBlank();
return $data;
}
$err = error_get_last();
consoleLog("<span>Error:</span> " . $err["message"]);
consoleLogBlank();
return false;
}
开发者ID:weslley17w,项目名称:habbo-asset-extractor,代码行数:18,代码来源:figures.php
示例18: __callback_createStreamContext
public function __callback_createStreamContext()
{
$stream = stream_context_create($this->_closure_createStreamContext_options);
stream_context_set_params($stream, $this->_closure_createStreamContext_params);
return $stream;
}
开发者ID:puzzlehttp,项目名称:puzzle,代码行数:6,代码来源:StreamAdapter.php
示例19: stream_notification_callback
<?php
require 'server.inc';
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max)
{
if ($notification_code == STREAM_NOTIFY_REDIRECTED) {
// $http_response_header is now a string, but will be used as an array
// by php_stream_url_wrap_http_ex() later on
$GLOBALS['http_response_header'] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
}
}
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
$responses = array("data://text/plain,HTTP/1.0 302 Found\r\nLocation: http://127.0.0.1:22345/try-again\r\n\r\n", "data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n");
$pid = http_server("tcp://127.0.0.1:22345", $responses, $output);
$f = file_get_contents('http://127.0.0.1:22345/', 0, $ctx);
http_server_kill($pid);
var_dump($f);
?>
==DONE==
开发者ID:gleamingthecube,项目名称:php,代码行数:20,代码来源:ext_standard_tests_http_bug69337.php
示例20: __set
function __set($key, $value)
{
$param = array($key => $value);
stream_context_set_params($this->getContext()->getResource(), $param);
parent::__set($key, $value);
}
开发者ID:Kinetical,项目名称:Kinesis,代码行数:6,代码来源:Collection.php
注:本文中的stream_context_set_params函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论