php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64921 Inconsistent stream_select() behavior for php://memory vs. php://temp
Submitted: 2013-05-25 00:11 UTC Modified: 2014-04-02 14:00 UTC
From: rdlowrey at gmail dot com Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.4.15 OS: Fedora 17
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: rdlowrey at gmail dot com
New email:
PHP Version: OS:

 

 [2013-05-25 00:11 UTC] rdlowrey at gmail dot com
Description:
------------
Streams of type php://memory cannot be represented as selectable descriptors 
where stream_select() is concerned. Attempting to do so will (rightly) trigger an 
E_WARNING along the lines of "Warning: stream_select(): cannot represent a stream 
of type MEMORY as a select()able descriptor in ..."

I would expect streams of type php://temp to behave the same way. However, this 
is not the case. Instead, php://temp streams are immediately readable (but do not 
evaluate to TRUE for feof($stream). These streams should either (1) trigger an 
error similar to that of php://memory or (2) not be represented as readable by 
stream_select().

Test script:
---------------
$stream = fopen('php://memory', 'r+');
$r = array($stream);
$w = $e = NULL;

stream_select($r, $w, $e, 0); // E_WARNING (as expected)

$stream = fopen('php://temp', 'r');
$r = array($stream);
$w = $e = NULL;

if (stream_select($r, $w, $e, 0)) {
    var_dump(feof($stream)); // this isn't readable and should never be called but it results in bool(false)
}

Expected result:
----------------
The test script should trigger two warnings and neither stream should report as 
readable.

Actual result:
--------------
php://temp streams do not trigger an error when used with stream_select() and are 
immediately reported as readable.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-05-25 17:09 UTC] rdlowrey at gmail dot com
UPDATE:

According to http://php.net/manual/en/wrappers.php.php php://temp DOES support  
stream_select(). However, if this is the case, the behavior described here is 
still incorrect because stream_select() reports that the descriptor is readable  
even though it has no readable data and feof($stream) === FALSE.
 [2014-04-02 14:00 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2014-04-02 14:00 UTC] mike@php.net
- select()'ing on a temp stream will convert it to a temp file (descriptor)
- regular files are always reported readable
- EOF is only detected on read

Summing up gives the described behaviour, which seems pretty fine to me.
 [2014-04-02 14:12 UTC] rdlowrey@php.net
Yeah you're right. I didn't fully understand the non-blocking behavior of regular files at the time of this report. This is definitely not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Oct 12 19:01:28 2024 UTC