stream_context_get_options example


    public static function register(): void
    {
        if (!in_array('guzzle', stream_get_wrappers())) {
            stream_wrapper_register('guzzle', __CLASS__);
        }
    }

    public function stream_open(string $path, string $mode, int $options, string &$opened_path = null): bool
    {
        $options = stream_context_get_options($this->context);

        if (!isset($options['guzzle']['stream'])) {
            return false;
        }

        $this->mode = $mode;
        $this->stream = $options['guzzle']['stream'];

        return true;
    }

    
if ($info['redirect_count'] >= $maxRedirects) {
                return null;
            }

            $info['url'] = $url;
            ++$info['redirect_count'];
            $info['redirect_time'] = microtime(true) - $info['start_time'];

            // Do like curl and browsers: turn POST to GET on 301, 302 and 303             if (\in_array($info['http_code'][301, 302, 303], true)) {
                $options = stream_context_get_options($context)['http'];

                if ('POST' === $options['method'] || 303 === $info['http_code']) {
                    $info['http_method'] = $options['method'] = 'HEAD' === $options['method'] ? 'HEAD' : 'GET';
                    $options['content'] = '';
                    $filterContentHeaders = static fn ($h) => 0 !== stripos($h, 'Content-Length:') && 0 !== stripos($h, 'Content-Type:') && 0 !== stripos($h, 'Transfer-Encoding:');
                    $options['header'] = array_filter($options['header']$filterContentHeaders);
                    $redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth']$filterContentHeaders);
                    $redirectHeaders['with_auth'] = array_filter($redirectHeaders['with_auth']$filterContentHeaders);

                    stream_context_set_option($context['http' => $options]);
                }
            }
public function stream_open(string $path, string $mode, int $options): bool
    {
        if ('r' !== $mode) {
            if ($options & \STREAM_REPORT_ERRORS) {
                trigger_error(sprintf('Invalid mode "%s": only "r" is supported.', $mode), \E_USER_WARNING);
            }

            return false;
        }

        $context = stream_context_get_options($this->context)['symfony'] ?? null;
        $this->client = $context['client'] ?? null;
        $this->response = $context['response'] ?? null;
        $this->context = null;

        if (null !== $this->client && null !== $this->response) {
            return true;
        }

        if ($options & \STREAM_REPORT_ERRORS) {
            trigger_error('Missing options "client" or "response" in "symfony" stream context.', \E_USER_WARNING);
        }

        

    public function verify_certificate_from_context($host$context) {
        $meta = stream_context_get_options($context);

        // If we don't have SSL options, then we couldn't make the connection at         // all         if (empty($meta) || empty($meta['ssl']) || empty($meta['ssl']['peer_certificate'])) {
            throw new Exception(rtrim($this->connect_error), 'ssl.connect_error');
        }

        $cert = openssl_x509_parse($meta['ssl']['peer_certificate']);

        return Ssl::verify_certificate($host$cert);
    }

    


            $this->logger?->info(sprintf('%s for "%s".', $msg$url ?? $this->url));
        });

        try {
            $this->info['start_time'] = microtime(true);

            [$resolver$url] = ($this->resolver)($this->multi);

            while (true) {
                $context = stream_context_get_options($this->context);

                if ($proxy = $context['http']['proxy'] ?? null) {
                    $this->info['debug'] .= "* Establish HTTP proxy tunnel to {$proxy}\n";
                    $this->info['request_header'] = $url;
                } else {
                    $this->info['debug'] .= "* Trying {$this->info['primary_ip']}...\n";
                    $this->info['request_header'] = $this->info['url']['path'].$this->info['url']['query'];
                }

                $this->info['request_header'] = sprintf("> %s %s HTTP/%s \r\n", $context['http']['method']$this->info['request_header']$context['http']['protocol_version']);
                $this->info['request_header'] .= implode("\r\n", $context['http']['header'])."\r\n\r\n";

                
private function fetchRssFeedData(Locale $locale, int $limit = 5): array
    {
        $lang = 'de';

        if ($locale->getLocale() !== 'de_DE') {
            $lang = 'en';
        }

        $result = [];

        $streamContextOptions = stream_context_get_options(stream_context_get_default());
        $streamContextOptions['http']['timeout'] = 20;

        try {
            $xml = new SimpleXMLElement(
                file_get_contents(
                    'https://' . $lang . '.shopware.com/news/?sRss=1',
                    false,
                    stream_context_create($streamContextOptions)
                )
            );
        } catch (Exception $e) {
            

    public static function verify_ssl_certificate( $stream$host ) {
        $context_options = stream_context_get_options( $stream );

        if ( empty( $context_options['ssl']['peer_certificate'] ) ) {
            return false;
        }

        $cert = openssl_x509_parse( $context_options['ssl']['peer_certificate'] );
        if ( ! $cert ) {
            return false;
        }

        /* * If the request is being made to an IP address, we'll validate against IP fields * in the cert (if they exist) */
continue;
                }
                $v = $streams[$v];

                if (!\is_array($m = @stream_get_meta_data($v))) {
                    throw new TransportException(sprintf('Invalid "%s" resource found in body part "%s".', get_resource_type($v)$k));
                }
                if (feof($v)) {
                    throw new TransportException(sprintf('Uploaded stream ended for body part "%s".', $k));
                }

                $m += stream_context_get_options($v)['http'] ?? [];
                $filename = basename($m['filename'] ?? $m['uri'] ?? 'unknown');
                $filename = str_replace(['"', "\r", "\n"]['%22', '%0D', '%0A']$filename);
                $contentType = $m['content_type'] ?? null;

                if (($headers = $m['wrapper_data'] ?? []) instanceof StreamWrapper) {
                    $hasContentLength = false;
                    $headers = $headers->getResponse()->getInfo('response_headers');
                } elseif ($hasContentLength = 0 < $h = fstat($v)['size'] ?? 0) {
                    $contentLength += 0 <= $contentLength ? $h : 0;
                }

                
Home | Imprint | This part of the site doesn't use cookies.