php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #43219 connection_status() can function properly without output
Submitted: 2007-11-08 23:28 UTC Modified: 2010-12-20 12:09 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (33.3%)
From: php at alterego dot dp dot ua Assigned:
Status: Open Package: Output Control
PHP Version: 5.2.5RC2 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
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 — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
16 + 15 = ?
Subscribe to this entry?

 
 [2007-11-08 23:28 UTC] php at alterego dot dp dot ua
Description:
------------
Please regard this comment seriously, it really contains information on how to fix 25266, 22072, 30301 and many other (NOT bogus) bugs under Apache SAPI.

From bug 25266 comment by iliaa@php.net:
> Apache provides a way for PHP to detect if connection was 
> aborted ONLY and ONLY when PHP is either reading data from 
> the user or writing back data.

That is not true.

This link contains description and code (mod_perl) on how to detect disconnection without flushing data:
http://www.webreference.com/programming/perl/cookbook/chap4/5.html

My untidy but WORKING solution was to add code given below to sapi_apache_flush function and call flush() function before connection_aborted() checks WITHOUT any output. Of course, it would be perfectly logical to add it to connection_aborted function itself, but I could not find any way to call SAPI-specific function from core.

Working code is:
int fd;
struct timeval tv = {0,0};
fd_set set;

if (server_context) {
    request_rec *r = SG(server_context);

    fd = ap_bfileno(r->connection->client, B_WR);

    if (fd >= 0) {
        FD_ZERO(&set);
        FD_SET(fd, &set);
        if (select(fd + 1, &set, NULL, NULL, &tv) >= 0 && FD_ISSET(fd, &set))
        {
            php_handle_aborted_connection();
        }
    }
}



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-20 12:09 UTC] jani@php.net
-Package: Tidy +Package: Output Control
 [2012-08-16 17:12 UTC] danclax at rambler dot ru
PHP 5.3.3, Apache 2.2.15, CentOS 6.2 x86 - issue reproducible! I can't believe it! Bug persists 5 years. For me it's vital feature.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Dec 03 19:01:24 2020 UTC