PHP Context Parameters


Introduction

Context parameters allow customization of access to filesystem and other stream wrappers. To configure a stream, PHP has stream_context_set_params() function.

Syntax

stream_context_set_params ( resource $stream_or_context , array $params ) : bool

$stream_or_context can be any of PHP's supported streams/wrappers/contexts

$params is an array with following properties. should be an associative array of the structure − $params['paramname'] = "paramvalue";

context parameters

notification − A user-defined callback to be called whenever a stream triggers a notification. Only for http:// and ftp:// stream wrappers.

The notification callback function has following syntax

syntax

stream_notification_callback ( int $notification_code , int $severity , string $message , int $message_code , int $bytes_transferred , int $bytes_max ) : void

options − Array of supported options corresponding to context/wrapper in use

Example

<?php
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
file_get_contents("http://php.net/contact", false, $ctx);
?>

Updated on: 21-Sep-2020

367 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements