php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32861 timeout is ignored in stream_select function
Submitted: 2005-04-27 21:53 UTC Modified: 2008-10-20 22:12 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: lew at mailduct dot com Assigned: pollita (profile)
Status: Not a bug Package: Filesystem function related
PHP Version: 5.0.4, 4.3.10 OS: FreeBSD 4.11-REL
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lew at mailduct dot com
New email:
PHP Version: OS:

 

 [2005-04-27 21:53 UTC] lew at mailduct dot com
Description:
------------
Timeouts are ignored in stream_select.  Instead, it always
returns with "1" as the number of streams affected, ignoring
any timeout seconds that are set.

This is true regardless of stream_set_blocking settings.

This may or may not be related to my reported FEOF problems:

pr #25649 (Sep 2003)
pr #32858 (Apr 2005)



Reproduce code:
---------------
$fp = fopen( '/var/log/maillog','r' );

##  Tried both ways, got same results
#stream_set_blocking( $fp,TRUE );
#stream_set_blocking( $fp,FALSE );

$r = array( $fp );

while( TRUE ) {
  $n = stream_select( $r,$w=NULL,$e=NULL,30 );
  if( $n===FALSE ) echo "stream_select = FALSE\n";
  else echo "stream_select = $n\n";
  echo fgets($fp);
  print( '.' );
}


Expected result:
----------------
Assuming no other program is writing to /var/log/maillog, I expect to see a timeout condition every 30 seconds, as such:

stream_select = FALSE

Actual result:
--------------
Instead, I see iterations of:

stream_select = 1

as fast as the system can execute the loop.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-28 00:35 UTC] pollita@php.net
From the stream_select() manual page:

The streams listed in the read array will be watched to see if characters become available for reading (more precisely, to see if a read will not block - in particular, a stream resource is also ready on end-of-file, in which case an fread() will return a zero length string). 


 [2005-04-28 07:45 UTC] lew at mailduct dot com
I believe that under the OS and PHP version given in the headers of this report, the stream timeout function is not working when used with fgets as well.  However, I will load the current PHP on the box and test again, to ensure I provide you with accurate and complete information and I'll open a new pr if necessary.

Let's close this one as Bogus.
 [2005-05-27 00:04 UTC] lew at mailduct dot com
I have now tested this using both PHP 4.3.11 and 5.0.4, and the bug remains.  My same prior notes apply.  Please review.
 [2005-07-28 20:26 UTC] lew at mailduct dot com
After testing with the latest php5 release, this still has a problem.  Let me try to be more succinct in summarizing...

When operating with wrapper_type of 'plainfile' (such as when tailing one or more files), the tv_sec and tv_usec (timeout) are ignored... because stream_select insists on classifying FEOF as an important event.  While this may be true for a socket event (socket close, for example... which is why we have socket_select instead), it is not true for a plainfile event.

Ask yourself this question -- How would you make use of the 'timeout' parameter when reading from a plainfile wrapper?  It would never come into play if FEOF awakens the stream_select call!  The purpose of stream_select is to let you multiplex streams... so you can WAIT for an action to take place on a stream (or a timeout).  If FEOF is allowed to awaken the select (rather than waiting for a timeout or for data to become available), then there's not much point to using that call...  You're forcing it to do [expensive] polling instead of relying on the select() interrupt structure to do the work for you.

My second argument is this:  Let's assume you insist FEOF should awaken the select.  If that's the case, then it still is not working correctly... because if I *add data* to a file after the select detected EOF, and then do a select again, it *still* thinks no data is available (and that we're still at EOF even though we're not).

This is VERY broken.
 [2005-07-29 01:56 UTC] sniper@php.net
Assigning to Sara who knows this stuff..

 [2005-11-07 00:02 UTC] sniper@php.net
Please try using this CVS snapshot:

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


 [2005-11-14 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2008-10-20 20:02 UTC] estoesunapija at hotmail dot com
Its been like a year since im waiting for this to be fixed!
 [2008-10-20 22:12 UTC] lbarnaud@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

This is expected behavior.

From PHP manual: The streams listed in the read  array will be watched to see if characters become available for reading (more precisely, to see if a read will not block [...]).

A read from a regular file will virtually never block, it will return an empty string instead. Actually stream_select() is only meant to be used with sockets, pipes, etc.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 21:01:29 2024 UTC