ID:               40933
 Updated by:       [EMAIL PROTECTED]
 Reported By:      loony at loonybin dot org
-Status:           Open
+Status:           Feedback
 Bug Type:         Streams related
 Operating System: Linux 2.6.20 - FC6
-PHP Version:      5.2.1
+PHP Version:      5.2CVS-2007-07-17
 New Comment:

This test script works for me with Apache 2.2 when I access it from two
different machines:

<html>
<body>
<pre>
<?php

function tail ($file, $timeout)
{
    $f = fopen ($file, "r");
    if (!$f) {
        return false;
    }
    if (!stream_set_blocking ($f, 0)) {
        return false;
    }

    $curDel = 0;
    while ($curDel < $timeout) {
        $s = fread ($f, 8192);
        if ($s) { // got data
            do {
                echo $s;
            } while ( $s = fread ($f, 8192) );
            flush();
            $curDel = 0;
        } else { // got no data
            sleep (1);
            $curDel += 1;
        }
    }
    fclose ($f);
}
echo getmypid() . " - " . date("s") . "\n";
flush();
tail ("/tmp/test", 15);
?>
</pre>
</body>
</html>

What SAPI are you using? I found problems with FastCGI and flush()..


Previous Comments:
------------------------------------------------------------------------

[2007-07-14 17:04:45] loony at loonybin dot org

Sorry about the ob_flush, it can be removed. The code came originally
from a larger application and I cut out as much as I could. Must have
missed the ob_flush. 

The problem is the same after the ob_flush has been removed.

I am not aware of any PHP version that this works on. I've tried from
4.0.xx to php5.2-200707122230 and none worked properly.

------------------------------------------------------------------------

[2007-07-14 09:14:43] [EMAIL PROTECTED]

Does that script work in any PHP version? I also get some E_NOTICE for
that ob_flush(); call..

------------------------------------------------------------------------

[2007-07-13 02:27:36] loony at loonybin dot org

Tried php5.2-200707122230 and the behavior does not seem to have
changed.

------------------------------------------------------------------------

[2007-07-12 21:16:39] [EMAIL PROTECTED]

Please try using this CVS snapshot:

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

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi



------------------------------------------------------------------------

[2007-03-28 04:32:29] loony at loonybin dot org

Description:
------------
Tail for php. Open the file, output the current content... then wait
for more - if no more content arrives, then return number of bytes read
after a while... 

Running 1 execution of this code works fine. Executing it from two
browsers at the same time blocks. 

Happens on Fedora Core 6 default 5.1.6 and also after upgrading to
5.2.1

Reproduce code:
---------------
http://ns1.loonybin.org/php/tail.tar.gz - 45 lines

Expected result:
----------------
See content of file printed immediately. If any content is appended to
the file within 15 seconds from request start, that content should be
printed as well. 

This works with 1 execution of the code. Should yield same result if
executed multiple times. 

Actual result:
--------------
1 run of the code works. Multiple executions however block on semop /
epoll_wait. 

semop(4358158, 0x15470c, 1)       = 0 <2.194313>
epoll_wait(16, {{EPOLLIN, {u32=2156798632, u64=13801426109869204136}}},
2, -1) = 1 <3.738842>

As soon as the first execution of the code has ended, the second will
run as expected and finish successfully (as long as max_execution_time
is not reached). 


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=40933&edit=1

Reply via email to