|  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
 [2013-05-25 00:11 UTC] rdlowrey at gmail dot com
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 

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 

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


Add a Patch

Pull Requests

Add a Pull Request


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

According to 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]
-Status: Open +Status: Not a bug
 [2014-04-02 14:00 UTC]
- 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]
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: Fri Jul 19 12:01:29 2024 UTC