Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> PHP

PHP Context Parameters

Giới thiệu

Tham số ngữ cảnh cho phép tùy chỉnh truy cập hệ thống tệp và stream wrapper khác. Để cấu hình stream, PHP có hàm stream_context_set_params().

Cú pháp

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

$stream_or_context có thể là bất kỳ stream/wrapper/context nào PHP hỗ trợ.

$params là mảng với các thuộc tính sau. Nên là mảng liên kết cấu trúc: $params['paramname'] = "paramvalue";

Tham số ngữ cảnh

  • notification - Callback user-defined gọi khi stream kích hoạt thông báo. Chỉ cho wrapper https:// và ftp://.

Hàm callback notification có cú pháp:

Cú pháp

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

options - Mảng tùy chọn hỗ trợ tương ứng context/wrapper dùng.

Ví dụ

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