From:             
Operating system: Linux/Windows
PHP version:      Irrelevant
Package:          Network related
Bug Type:         Bug
Bug description:PHP does not notice user abort

Description:
------------
Referencing http://php.net/manual/en/features.connection-handling.php



I understand that providing PHP is writing to or reading from the web
server connection, a registered shutdown function should be called should
the client abort.



I have never known this to be the case.



I attach a simple script. It attempts to sleep then write back to the
client. It has a registered shutdown function that checks
connection_status() and connection_aborted(). According to my syslog
however, the full script executes followed by the shutdown function which
says the user is still connected, despite my pressing the browser stop
button immediately after placing the request.



I have tested this on Windows using Lighttpd with PHP 5.2, and on Ubuntu
with Apache preforking PHP 5.3. Both exhibit the same behaviour.



These tests were conducted with ignore_user_abort(true) and (false) - no
difference observed so I removed it.



Test script:
---------------
<?php

syslog(LOG_DEBUG, 'Connection opened');

register_shutdown_function('shutdown');

$usleep = 2000000;

for ($i=0; $i < 100; $i++) {

    $str[$i] = '';

    for ($x=0; $x < 1000; $x++) {

        $str[$i] .= 'flubber';

    }

}

if (isset($_REQUEST['usleep'])) {

    $usleep = (int) $_REQUEST['usleep'];

}

usleep($usleep);

syslog(LOG_DEBUG, 'Completed usleep()');

echo "Thanks for waiting\n";

print_r($str);

ob_end_flush();

syslog(LOG_DEBUG, 'ob_end_flush() called');

flush();

syslog(LOG_DEBUG, 'Have flushed()');

// We get to this part regardless of having already pressed STOP

function shutdown()

{

    echo "Thanks for waiting\n";

    flush();

    syslog(LOG_DEBUG, 'Echo completed');

//    sleep(1);

    syslog(LOG_DEBUG, 'Have slept');

    syslog(LOG_DEBUG, 'Shutdown detected.');

    syslog(LOG_DEBUG, "The result of connection_status() is: " .
connection_status());

    // The above is almost always 0

    if (connection_aborted()) {

        // This almost never happens!

        syslog(LOG_DEBUG, 'The connection has aborted');

    } else {

        // This almost always happens!

        syslog(LOG_DEBUG, 'The connection remains');

    }

}



Expected result:
----------------
syslog entries should stop when PHP writes to the client socket and notes
that the client has sent an abort signal. Then, the shutdown function
should show that the connection_status() is no longer 0, and that the
connection_aborted() method returns true.

Actual result:
--------------
syslog entries continue to Have flushed(), then show that "The result of
connection_status() is: 0." and "The connection remains."



This should not be the case. Perhaps Apache is not sending the appropriate
signal, yet neither is Lighttpd..?

-- 
Edit bug report at http://bugs.php.net/bug.php?id=54062&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=54062&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=54062&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=54062&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=54062&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=54062&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=54062&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=54062&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=54062&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=54062&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=54062&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=54062&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=54062&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=54062&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=54062&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54062&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54062&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=54062&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=54062&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=54062&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=54062&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=54062&r=mysqlcfg

Reply via email to