PHP stream_context_get_params() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Stream

Definition

In PHP, stream_context_get_params() returns the parameters stored on a stream or context, and it also includes the current options under an options key.

Parameters are separate from wrapper options. The most common parameter is notification, which names a callback for HTTP or FTP progress events.

Syntax

Call stream_context_get_params() with the values you need. Start with this line.

PHP
$params = stream_context_get_params($context);
CallWhat it does
stream_context_get_params($ctx)Returns parameters plus an options array for the context.
stream_context_get_params($fp)Reads params from a stream resource that carries a context.
$params["notification"]Typical key when a notification callback was set.

Even if you only set options, get_params() still returns an array with an options key. That makes it a handy all-in-one inspector during learning.

Library declarations
PHP
stream_context_get_params(resource $context): array

Parameters

ParameterDescription
contextRequired. A stream resource or a context resource.

Return Value

Return ValueDescription
arrayAssociative array of parameters. Includes an options key with the wrapper options array.

PHP Examples

Example 1 — Read Params From a Plain Context

Create a context with HTTP options only, then list the keys returned by get_params().

PHP
<?php
$ctx = stream_context_create([
    "http" => ["method" => "GET"],
]);

$params = stream_context_get_params($ctx);
echo implode(",", array_keys($params)), PHP_EOL;
echo $params["options"]["http"]["method"], PHP_EOL;

How It Works

  1. The context is created with one HTTP option and no special parameters.
  2. get_params() still returns an array.
  3. The only top-level key here is options.
  4. We print the nested HTTP method from that options section.

Example 2 — Inspect a Notification Parameter

Set a notification callback name, then read it back with get_params().

PHP
<?php
$ctx = stream_context_create();
stream_context_set_params($ctx, [
    "notification" => "stream_notification_callback",
]);

$params = stream_context_get_params($ctx);
echo $params["notification"], PHP_EOL;
echo isset($params["options"]) ? "has_options" : "no_options", PHP_EOL;

How It Works

  1. stream_context_set_params() stores the notification entry.
  2. get_params() returns that parameter together with options.
  3. We print the callback name string.
  4. The options key is present even when it is still empty.

Example 3 — Compare get_params() and get_options()

Show that get_options() is the options section only, while get_params() wraps more information.

PHP
<?php
$ctx = stream_context_create([
    "http" => ["user_agent" => "Compare/1"],
]);
stream_context_set_params($ctx, [
    "notification" => "stream_notification_callback",
]);

$opts = stream_context_get_options($ctx);
$params = stream_context_get_params($ctx);

echo $opts["http"]["user_agent"], PHP_EOL;
echo $params["options"]["http"]["user_agent"], PHP_EOL;
echo $params["notification"], PHP_EOL;

How It Works

  1. Both helpers can see the same user_agent value.
  2. get_options() returns the nested options array directly.
  3. get_params() nests those options under options and also returns notification.
  4. Printing all three lines shows how the two APIs relate.

Frequently Asked Questions

It returns the parameters on a context or stream, including an options key that holds the wrapper options.
Common ones are notification (callback name) and options. Supported parameters depend on the wrappers you use.
get_options() returns only wrapper options. get_params() returns parameters and also embeds the options array.
No. You can set and read parameters locally without opening a network URL.
stream_context_create(), stream_context_set_params(), and related context helpers store them.

Next: stream_context_set_default()

stream_context_set_default() replaces the options on the default stream context used by fi.

stream_context_set_default() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful