Supported Versions: PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8
Retrieve options for a stream/wrapper/context
<?php stream_context_get_options(resource $stream_or_context): array
<?php $io->write('Checking https connectivity to packagist: ', false);
$this->outputResult($this->checkHttp('https', $config));
$opts = stream_context_get_options(StreamContextFactory::getContext('http://example.org'));
if (!empty($opts['http']['proxy'])) {
$io->write('Checking HTTP proxy: ', false);
$this->outputResult($this->checkHttpProxy());
<?php public function testGetContext($expectedOptions, $defaultOptions, $expectedParams, $defaultParams)
{
$context = StreamContextFactory::getContext('http://example.org', $defaultOptions, $defaultParams);
$options = stream_context_get_options($context);
$params = stream_context_get_params($context);
$this->assertEquals($expectedOptions, $options);
<?php $_SERVER['HTTP_PROXY'] = 'http://proxyserver/';
$context = StreamContextFactory::getContext('http://example.org', array('http' => array('method' => 'GET', 'header' => 'User-Agent: foo')));
$options = stream_context_get_options($context);
$this->assertEquals(array('http' => array(
'proxy' => 'tcp://proxyserver.net:3128',
<?php $_SERVER['no_proxy'] = 'foo,example.org';
$context = StreamContextFactory::getContext('http://example.org', array('http' => array('method' => 'GET', 'header' => 'User-Agent: foo')));
$options = stream_context_get_options($context);
$this->assertEquals(array('http' => array(
'method' => 'GET',
<?php $_SERVER['no_proxy'] = '*';
$context = StreamContextFactory::getContext('http://example.org', array('http' => array('method' => 'GET', 'header' => 'User-Agent: foo')));
$options = stream_context_get_options($context);
$this->assertEquals(array('http' => array(
'method' => 'GET',
<?php $_SERVER['http_proxy'] = 'http://username:password@proxyserver.net:3128/';
$context = StreamContextFactory::getContext('http://example.org', array('http' => array('method' => 'GET', 'header' => array('User-Agent: foo', "X-Foo: bar"), 'request_fulluri' => false)));
$options = stream_context_get_options($context);
$this->assertEquals(array('http' => array(
'proxy' => 'tcp://proxyserver.net:3128',
<?php $_SERVER['http_proxy'] = 'http://username:password@proxyserver.net';
$context = StreamContextFactory::getContext('https://example.org', array('http' => array('method' => 'GET', 'header' => 'User-Agent: foo')));
$options = stream_context_get_options($context);
$this->assertEquals(array('http' => array(
'proxy' => 'tcp://proxyserver.net:80',
<?php if (extension_loaded('openssl')) {
$context = StreamContextFactory::getContext('http://example.org', array('http' => array('header' => 'User-Agent: foo')));
$options = stream_context_get_options($context);
$this->assertEquals(array('http' => array(
'proxy' => $expected,
<?php ),
);
$context = StreamContextFactory::getContext('http://example.org', $options);
$ctxoptions = stream_context_get_options($context);
$this->assertEquals(end($expectedOptions['http']['header']), end($ctxoptions['http']['header']));
}
<?php $method = $this->method;
$context = \stream_context_get_options($socket);
if (isset($context['ssl']['crypto_method'])) {
$method = $context['ssl']['crypto_method'];
}
<?php $ref->setAccessible(true);
$socket = $ref->getValue($server);
$context = stream_context_get_options($socket);
$this->assertEquals(array('socket' => array('backlog' => 4)), $context);
<?php $ref->setAccessible(true);
$socket = $ref->getValue($server);
$context = stream_context_get_options($socket);
$this->assertEquals(array('socket' => array('backlog' => 511)), $context);
<?php $peer = new Promise(function ($resolve, $reject) use ($server) {
$server->on('connection', function (ConnectionInterface $connection) use ($resolve) {
$resolve(stream_context_get_options($connection->stream));
});
});
<?php $peer = new Promise(function ($resolve, $reject) use ($server) {
$server->on('connection', function (ConnectionInterface $connection) use ($resolve) {
$resolve(stream_context_get_options($connection->stream));
});
});
<?php $peer = new Promise(function ($resolve, $reject) use ($socket) {
$socket->on('connection', function (ConnectionInterface $connection) use ($resolve) {
$resolve(stream_context_get_options($connection->stream));
});
});