Bug #76605 [Opn]: stream_notification_callback is not being called

From: Date: Wed, 11 Jul 2018 08:26:11 +0000
Subject: Bug #76605 [Opn]: stream_notification_callback is not being called
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216272@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76605&edit=1

 ID:                 76605
 User updated by:    gbuza at inviqa dot com
 Reported by:        gbuza at inviqa dot com
 Summary:            stream_notification_callback is not being called
 Status:             Open
 Type:               Bug
 Package:            Streams related
 Operating System:   ArchLinux, kernel 4.17.4
 PHP Version:        7.2.7
 Block user comment: N
 Private report:     N

 New Comment:

> It's only used for actual streams like FTP and HTTP.
If it's used for network streams, then could you please add this info to the documentation?

> Note half of the STREAM_NOTIFYs don't make sense for files.
I don't see it as a problem, because these constants represents events. If such an event
doesn't occur, then the callback function shouldn't be called.

So if this case is not a bug, then please consider it as a feature request. It would be very
powerful to handle streams decoupled from source or destination (regardless of whether it's a
file on disk, network resource or an in-memory stream) as much as possible.


Previous Comments:
------------------------------------------------------------------------
[2018-07-10 19:59:08] requinix@php.net

It's only used for actual streams like FTP and HTTP. Note half of the STREAM_NOTIFYs don't
make sense for files.

Either
a) This is a request to add notifications to other stream types, like files
b) This is a doc bug and the stream_notification_callback() or assorted stream *:// pages should be
amended to specify how/when a notification callback is used

------------------------------------------------------------------------
[2018-07-10 13:29:51] gbuza at inviqa dot com

Description:
------------
When stream notification callback is used with fopen() function, it does not get called at all.

Test script:
---------------
<?php

file_put_contents('/tmp/input.txt', 'foo bar baz');

function stream_notification_callback($notification_code, $severity, $message, $message_code,
$bytes_transferred, $bytes_max) {
	die('It made progress.');
}

$context = stream_context_create();
stream_context_set_params($context, ['notification' =>
'stream_notification_callback']);
$input = fopen('/tmp/input.txt', 'r', false, $context);
$output = fopen('/tmp/output.txt', 'w');
stream_copy_to_stream($input, $output);
fclose($input);
fclose($output);


Expected result:
----------------
I expect to see the message "It made progress." on the standard output and the file
/tmp/output.txt should not exist.

Actual result:
--------------
No message is displayed and the file /tmp/output.txt is created.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=76605&edit=1


Thread (5 messages)

« previous php.bugs (#216272) next »