stream_notification_callback

A callback function for the notification context parameter

Syntax

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

Parameters

notification_code

One of the STREAM_NOTIFY_* notification constants.

severity

One of the STREAM_NOTIFY_SEVERITY_* notification constants.

message

Passed if a descriptive message is available for the event.

message_code

Passed if a descriptive message code is available for the event.

The meaning of this value is dependent on the specific wrapper in use.

bytes_transferred

If applicable, the bytes_transferred will be populated.

bytes_max

If applicable, the bytes_max will be populated.

Return

No value is returned.

Examples

<?

function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max)
{
    switch($notification_code)
    {
        case STREAM_NOTIFY_RESOLVE:
        case STREAM_NOTIFY_AUTH_REQUIRED:
        case STREAM_NOTIFY_COMPLETED:
        case STREAM_NOTIFY_FAILURE:
        case STREAM_NOTIFY_AUTH_RESULT:
            var_dump($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max);
            break;
        case STREAM_NOTIFY_CONNECT:
            echo "connect";
            break;
        case STREAM_NOTIFY_MIME_TYPE_IS:
            echo "mime type: " . $message;
            break;
        case STREAM_NOTIFY_FILE_SIZE_IS:
            echo "file size: " . $bytes_max;
            break;
        case STREAM_NOTIFY_REDIRECTED:
            echo "redirected: " . $message . "\n";
            break;
        case STREAM_NOTIFY_PROGRESS:
            echo "progress: " . $bytes_transferred;
            break;
    }
    echo "\n";
}

$stream_or_context = stream_context_create();
$params = array("notification" => "stream_notification_callback");

stream_context_set_params($stream_or_context, $params);

$filename = "http://osbo.com/";
$use_include_path = false;

file_get_contents($filename, $use_include_path, $stream_or_context);

?>
connect
mime type: text/html
file size: 707
redirected: https://osbo.com/

connect
mime type: text/html; charset=UTF-8
progress: 0
progress: 0
progress: 8192
progress: 14994
progress: 23186
progress: 31378
progress: 39570
progress: 47762
progress: 55954
progress: 64146
progress: 72338
progress: 80530
progress: 88722
progress: 96914
progress: 105106
progress: 113298
progress: 121490
progress: 129682
progress: 137874
progress: 146066
progress: 148918
progress: 148923

stream_bucket_append

stream_bucket_make_writeable

stream_bucket_new

stream_bucket_prepend

stream_context_create

stream_context_get_default

stream_context_get_options

stream_context_get_params

stream_context_set_default

stream_context_set_option

stream_context_set_params

stream_copy_to_stream

stream_filter_append

stream_filter_prepend

stream_filter_register

stream_filter_remove

stream_get_contents

stream_get_filters

stream_get_line

stream_get_meta_data

stream_get_transports

stream_get_wrappers

stream_is_local

stream_isatty

stream_register_wrapper

stream_resolve_include_path

stream_select

stream_set_blocking

stream_set_chunk_size

stream_set_read_buffer

stream_set_timeout

stream_set_write_buffer

stream_socket_accept

stream_socket_client

stream_socket_enable_crypto

stream_socket_get_name

stream_socket_pair

stream_socket_recvfrom

stream_socket_sendto

stream_socket_server

stream_socket_shutdown

stream_supports_lock

stream_wrapper_register

stream_wrapper_restore

stream_wrapper_unregister

PHP

Home Menu