php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76605 stream_notification_callback is not being called
Submitted: 2018-07-10 13:29 UTC Modified: 2021-07-28 09:14 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: gbuza at inviqa dot com Assigned: cmb (profile)
Status: Duplicate Package: Streams related
PHP Version: 7.2.7 OS: ArchLinux, kernel 4.17.4
Private report: No CVE-ID: None
 [2018-07-10 13:29 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-10 19:59 UTC] 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-11 08:26 UTC] gbuza at inviqa dot com
> 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.
 [2018-07-12 22:06 UTC] cmb@php.net
-Type: Bug +Type: Feature/Change Request
 [2018-07-12 22:06 UTC] cmb@php.net
> If it's used for network streams, then could you please add this
> info to the documentation?

Done via <http://svn.php.net/viewvc?view=revision&revision=345305>.

Changing to feature request.

Related to bug #52811, by the way.
 [2021-07-28 09:14 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2021-07-28 09:14 UTC] cmb@php.net
Actually, this is a duplicate of bug #52811.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 18:01:29 2024 UTC