php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52811 the notification callback method never gets call when using socket streams
Submitted: 2010-09-10 12:55 UTC Modified: 2021-07-28 09:13 UTC
Votes:9
Avg. Score:4.6 ± 0.7
Reproduced:9 of 9 (100.0%)
Same Version:3 (33.3%)
Same OS:7 (77.8%)
From: recycling dot sp dot am at gmail dot com Assigned:
Status: Open Package: Streams related
PHP Version: 5.3.3 OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: recycling dot sp dot am at gmail dot com
New email:
PHP Version: OS:

 

 [2010-09-10 12:55 UTC] recycling dot sp dot am at gmail dot com
Description:
------------
At least when the context is set to 'tcp' and the socket is opened with stream_socket_client, the callback method defined with the notification parameters of stream_context_set_params never get called. 

And the current documentation is pointless regarding which wrapper actually support the notifications. 
As far as I can see ftp and http wrappers support it but tcp socket (or even file://) don't.

Callback notification function is the way to perform efficient and advanced monitoring on socket.
It should be invoked for the following events:
STREAM_NOTIFY_RESOLVE Yes
STREAM_NOTIFY_CONNECT Yes
STREAM_NOTIFY_AUTH_REQUIRED No
STREAM_NOTIFY_MIME_TYPE_IS No
STREAM_NOTIFY_FILE_SIZE_IS No
STREAM_NOTIFY_REDIRECTED No
STREAM_NOTIFY_PROGRESS 	Yes but optional 
STREAM_NOTIFY_COMPLETED Yes 
STREAM_NOTIFY_FAILURE Oh Yes
STREAM_NOTIFY_AUTH_RESULT No
STREAM_NOTIFY_SEVERITY_INFO Yes
STREAM_NOTIFY_SEVERITY_WARN Yes
STREAM_NOTIFY_SEVERITY_ERR Yes

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

// define our callback method
function snc() { var_dump(func_get_args()); }

$ctx= stream_context_create();
stream_context_set_params($ctx, array("notification" => "snc"));
$uri= "htttp://www.example.net";
$socket = stream_socket_client($uri, $errno, $errstr, 0, STREAM_CLIENT_CONNECT, $ctx); // snc should already have been called here for at least connection and resolv.
$line =fgets($socket); // get one line.
fclose($socket); // close the connection. 
// Run the above lines and snc() never gets called.

Expected result:
----------------
1. Update documentation to let developers know the current state of the callback support 
2. Have the callback method invoked when using socket streams for the following events (where applicable).


Actual result:
--------------
The scn method never gets called.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-21 12:34 UTC] cataphract@php.net
-Assigned To: +Assigned To: cataphract
 [2017-10-24 07:56 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: cataphract +Assigned To:
 [2021-07-28 09:13 UTC] cmb@php.net
-Type: Bug +Type: Feature/Change Request
 [2021-07-28 09:13 UTC] cmb@php.net
> As far as I can see ftp and http wrappers support it but tcp
> socket (or even file://) don't.

Right; this is documented[1] now.

[1] <https://www.php.net/manual/en/function.stream-context-set-params.php#refsect1-function.stream-context-set-params-parameters>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 13 23:01:26 2024 UTC