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

1

<?

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: 1008
progress: 0
progress: 1008
progress: 9200
progress: 16002
progress: 24194
progress: 32386
progress: 40578
progress: 48770
progress: 56962
progress: 65154
progress: 65538
progress: 66906
progress: 75098
progress: 81900
progress: 90092
progress: 98284
progress: 106476
progress: 114668
progress: 122860
progress: 131052
progress: 139244
progress: 147436
progress: 155628
progress: 160672
HomeMenu