Home >Backend Development >PHP Tutorial >PHP context parameters

PHP context parameters

WBOY
WBOYforward
2023-08-31 09:49:06913browse

PHP context parameters

Introduction

Context parameters allow customizing access to the file system and other stream wrappers. To configure streams, PHP has the stream_context_set_params() function.

Syntax

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

$stream_or_context can be any stream/wrapper/context supported by PHP

$params is an array with the following properties. Should be an associative array of structures - $params['paramname'] = "paramvalue";

Context Parameters

Notifications - User defined whenever a stream triggers a notification The callback will be called. Applies only to http:// and ftp:// stream wrappers.

Notification callback functions have the 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 the 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);
?>

The above is the detailed content of PHP context parameters. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete