php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50856 stream_set_blocking doesn't work with fopen
Submitted: 2010-01-27 09:28 UTC Modified: 2014-04-01 09:31 UTC
Votes:6
Avg. Score:4.2 ± 0.7
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:2 (40.0%)
From: info at netzkontrast dot com Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.3.1 OS: Ubuntu/Suse/Linux
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
8 + 35 = ?
Subscribe to this entry?

 
 [2010-01-27 09:28 UTC] info at netzkontrast dot com
Description:
------------
I tried the following code with different PHP-versions (5.3.1 + 5.2.8) on different Systems (one ubunto-box and a suse-box

i'm totaly stuck, is there anything i'm missing?

-- i have prepared some testscripts 
- streamContent.php (used for testoutput)
- streamfiletest.php -> not working
- streamSocketTest.php -> not working
- streamFsockTest.php -> working






Reproduce code:
---------------
<?php    // streamfiletest.php
$filename = "/home/tests/myfile.txt";
$handle = fopen($filename, "r");
stream_set_blocking($handle, 0);
$metadata = stream_get_meta_data($handle);
var_dump($metadata['blocked']) // should return 0     ?>

<?php // streamContent.php
for($i = 10;$i;--$i) {
    echo ". ";
    if (ob_get_contents())ob_flush();flush();usleep(1000000);  
}     ?>

<?php //streamSocketTest.php 
$handle = fopen("http://localhost/streamContent.php", "r");
stream_set_blocking($handle, 0); 
while(!feof($handle)) {
    echo  fread($handle, 100);
       echo "-";usleep(80000); 
}   ?>

<?php // streamFsockTest.php 
$handle = fsockopen("localhost", 80);
stream_set_blocking($handle, 0);
fputs($handle, "GET /streamcontent.php HTTP/1.0\r\nHost: mp.devel\r\nConnection: keep-alive\r\n\r\n");
while(!feof($handle)) {
    echo  fgets($handle, 10);
       echo "-";usleep(80000); 
}?>

Expected result:
----------------
streamfiletest.php: 0
streamSocketTest.php: . -----------. ------------. (etc..)
streamFsockTest.php: . -----------. ------------. (etc..)

Actual result:
--------------
streamfiletest.php: 1
streamSocketTest.php: . -. -. -
streamFsockTest.php: . -----------. ------------.  

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-27 09:32 UTC] info at netzkontrast dot com
there is a typo in streamFsockTest.php 

instead of: fputs($handle, "GET /streamcontent.php HTTP/1.0\r\nHost: mp.devel\r\nConnection: keep-alive\r\n\r\n");

it should be:
fputs($handle, "GET /streamcontent.php HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n");
 [2010-01-28 08:45 UTC] jani@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2010-01-28 15:55 UTC] info at netzkontrast dot com
fopen is still blocking with 

local files ('wrapper_type' => string 'plainfile'
and URL's 'wrapper_type' => string 'cURL'

looks like stream_set_blocking gets totaly ignored from fopen

while non_blocking reads still work with fsockopen, and reading from STDIN
 [2010-01-29 14:21 UTC] info at netzkontrast dot com
i think it's interesting to mention that stream_set_blocking($stream, 0) returns true...

i did poke around a bit in streamsfuncs.c on line 1321 (and plain_wrapper.c line 559ff) - and if i'm interpreting it correct. returning truly means that the o_NONBLOCK-flag gets correctly set at the corresponding open-command. 

right now i'm not sure were to look next. Think i need to read a lot more code ,-)
 [2014-04-01 09:31 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2014-04-01 09:31 UTC] mike@php.net
(On Linux) O_NONBLOCK is generally ignored for regular files (except when used with mandatory file locking).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 14 14:01:26 2024 UTC