php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40933 Streams blocking under concurrent access
Submitted: 2007-03-28 04:32 UTC Modified: 2007-07-24 01:00 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: loony at loonybin dot org Assigned:
Status: No Feedback Package: Streams related
PHP Version: 5.2CVS-2007-07-17 OS: Linux 2.6.20 - FC6
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-03-28 04:32 UTC] 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). 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-13 02:27 UTC] loony at loonybin dot org
Tried php5.2-200707122230 and the behavior does not seem to have changed.
 [2007-07-14 09:14 UTC] jani@php.net
Does that script work in any PHP version? I also get some E_NOTICE for that ob_flush(); call..
 [2007-07-14 17:04 UTC] 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-16 22:24 UTC] jani@php.net
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()..
 [2007-07-24 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".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC