php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17774 connection_status() not returning correct result
Submitted: 2002-06-15 16:37 UTC Modified: 2002-12-13 04:05 UTC
Votes:6
Avg. Score:5.0 ± 0.0
Reproduced:5 of 6 (83.3%)
Same Version:3 (60.0%)
Same OS:5 (100.0%)
From: neil at mpfreescene dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: PHP/4.3.0RC3 OS: FREEBSD 4.7-STABLE
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: neil at mpfreescene dot com
New email:
PHP Version: OS:

 

 [2002-06-15 16:37 UTC] neil at mpfreescene dot com
Im runnig PHP 4.3.0CVS on Apache 2.x

My problem is that I have written a script that sends content-dispostion headers to the browser and starts a download.

When they user cancels the downloads, connection_status() is not reflecting this.  I would assume that it shuold return a value of 1, USER ABORTED.

Instead the script continues to run in the background by sending the file somewhere (limbo?).  The script then reaches the end and terminates normally.

After the script has terminated normally the value for connection_status() is still set at 0 NORMAL.

Ive registered a shutdown function and tried all different methods like connection_aborted() which is FALSE, ive set ignore_user_abort() to TRUE and FALSE, but still alwasy the same result.

A problem arrises that it is entering false information to my weblogs, i.e. its saying that the entire file was transferred when indeed it was canceled half way through.

Im reading the file with fread() in 1K chunks and flushing in between, so as the script does not buffer everything and terminate prematurly, this is verified by the dump I have constructed at the end of the script to tell me what connection_status() is saying, which doesnt get written until you press to cancel the download or complete the download, so the script is definatly midway in progress at that time.


Ive read in teh user contributed notes of somebody else expierencing the same problem as me, that was back in FEB-2002.  The hack he has written to use netstat is far to resource intensive.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-15 19:51 UTC] sniper@php.net
There's already some reports about this. But it's nice to have another.

 [2002-06-29 20:52 UTC] neil at mpfreescene dot com
Just thought id enquire a little about this Bug, has it been a bug fora  long time?  Do you think it will be sorted any time soon ?

Do you think we may see it repaired for PHP 4.3.0-STABLE ?
 [2002-07-07 13:10 UTC] david at hexstream dot f9 dot co dot uk
Has this bug been looked in to at all?
Under FreeBSD, connection_status /always/ returns 0.
I've never tried it with any other flavours of BSD.

Regards,
David.
 [2002-09-25 07:38 UTC] neil dot doody at talk21 dot com
According to Bug #17265 this problem should be fixed rite?

Well I downloaded the latest CVS like 5 minutes ago.

THe following code snippets should return into a file that the connection was aborted, if this function was really fixed, rite?? well the outputs I am getting into my temp files to check the output of the script is "6077440 - 6076648 - 0 - not aborted - Keep-Alive"

Heres the script :-


        while(!feof($pl_of) and !connection_aborted()) {
                $pl_buffer = fread($pl_of, 1024);
                echo($pl_buffer);
                flush();
                $pl_sent = $pl_sent + 1024;
        }


        fclose ($pl_of);
        if ($pl_sent >= $pl_filesize){
                $pl_totalsent = "100%";
        }else{
                $pl_totalsent = round((100 / $pl_filesize * $pl_sent),2) . "%";
        }
        if (connection_aborted() == true){
                $temp = 'aborted';
        }else{
                $temp = 'not aborted';
        }

        $pl_totalsent = "$pl_sent - $pl_filesize - " . connection_status() . " -
 " . $temp . " - " . $_SERVER['HTTP_CONNECTION'];
 [2002-09-25 08:31 UTC] neil dot doody at talk21 dot com
I found there may be flaws with that code, so I wrote something else to test if the function was fixed, and it appears not, here is the code, if somebody cancels I would expect it to put '0' into wank.txt :-

<?
function exitfp() {
    $fp = fopen("wank.txt","w");
    fputs($fp, connection_status());
    fclose($fp);
}
register_shutdown_function('exitfp');

if(connection_aborted() != true){print "0";}
flush();
ignore_user_abort(true);
$m = '50';
while(connection_aborted() != true and $m > $a){
    sleep('1');
    print connection_status();
    flush();
    $a = $a + 1;
}

exitfp();

?>
 [2002-09-25 08:33 UTC] neil dot doody at talk21 dot com
Oh yeah, running that script, if I press the STOP button halfway through, after a while it will output "0" into wank.txt, which is wrong, it should put 2 is it? for connection closed.
 [2002-09-25 12:40 UTC] neil dot doody at talk21 dot com
An ammendmant to my last two posts.

I would expect the script to put a '1' into wank.txt if somebody presses the STOP button on there browser.

However the output I am getting is a '0' to say it disconnected regulary.
 [2002-09-29 22:47 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

Using latest CVS snapshot I cannot replicate the problem you've described. According to http://www.php.net/manual/en/features.connection-handling.php
0 - NORMAL, and 0 is what gets printed to the browser. Upon untimely termination of script, 1 is written to the output file, which means that connection was aborted.
 [2002-09-30 14:33 UTC] neil at mpfreescene dot com
This is an old posting of the bug, it was back in the days when I was with rackshack and running freebsd 4.5-STABLE.

I am now running freebsd 4.7-RELEASE 2 and amn with a different ISP, thus a totally different machine.

From your very latest CVS, I just downloaded and installed 5 minutes ago this error is still occuring.

In fact your latest version is even worse, now the script, which I will detail below doesnt print anything in the browser it just waits, and you press stop say after 5 seconds, approx 45 seconds later [thats a total of 50 1 second sleep attempts] the script writes to the outpout file the connection_status, which is a 0, this is saying that the script finsihed normally, this is WRONG according to your own manual of which it shgould report connection status 1, which is unatural termination of the script.

This bug is not fixed, it cannot be me I have been through all flavours and rebuilds of freebsd and every time the same error!

This is the script, still the same as it was before the latest cvs install that now doesnt display anything, you can view this script at http://admin.mghost.net/~neil/test/index.php, the output file is http://admin.mghost.net/~neil/test/wank.txt.


<?
function exitfp() {
    $fp = fopen("wank.txt","w");
    fputs($fp, connection_status());
    fclose($fp);
}
register_shutdown_function('exitfp');

if(connection_aborted() != true){print "0";}
flush();
ignore_user_abort(true);
$m = '50';
while(connection_aborted() != true and $m > $a){
    sleep('1');
    print connection_status();
    flush();
    $a = $a + 1;
}

exitfp();

?>
 [2002-09-30 14:43 UTC] iliaa@php.net
If you did a clean install you have output buffering enabled, meaning that PHP won't send the browser data until it filled the buffer of 4k or the script has stopped running. This is why it does not output anything right away. The other 'problem' can be explain by the fact you likely have 'ignore_user_abort' enabled, meaning that the script will run till completion even if the user connection was terminated or timed out.
 [2002-09-30 15:00 UTC] neil at mpfreescene dot com
Hmm, I probably look a bit thick rite now, but belive I had tried both values of ignore_user_abort, being set to false and true, but alwasy the same result, oops on my part for not realins to change it back to false, I did that and still the same result.

I assume that you mean by output_buffers being set to on, is in teh php.ini ?

Well This is a clipit of my php.ini

; a value for this directive (e.g., output_buffering=4096).
output_buffering = Off


I havnt changed my php.ini in all my installs [/usr/local/lib/php.ini] so that has been always set to Off.

So anyway, ive tried with the ignore_user_abort(false); set and still it ignores the user abort and 50 seconds later produces a file that contains a '0'.

I havnt changed anything since the last CVS a few days/weeks ago, yet it is no longer displaying a 0 in the browser it is just going with behaviour like it is buffering it, like you already suggested.
 [2002-09-30 15:05 UTC] iliaa@php.net
Do you have output compression enabled, whether via PHP or via Apache (mod_gzip module for example) ?
 [2002-09-30 15:17 UTC] neil at mpfreescene dot com
Yes I am, however it didnt do this on the CVS install under a week ago, thats irrespective of my problem, Im not all that fussed wether it displays the zero or not, it really doesnt assist me in my long standing problem with the code I want to write that depends on the STOP buttong being pressed and detecting this.
 [2002-10-08 04:51 UTC] neil at mpfreescene dot com
Just to keep you informed on this, I have now deleted my old install of apache and installed a FRESH copy of apache 2.0.43 and the latest CVS at the time, im still using the same php.ini file.

The problem still exists in its entirety.
 [2002-12-07 08:47 UTC] neil at mpfreescene dot com
Okay, time has moved on, plenty of new versions have come out, ive kept up to the very latest all along, alas, as expected, it still doesnt work.

Can I just get a clarification of what should happen when a user presses the stop button on the following script ?  My guess is that it should put a 1 or a 2 into the file, not a 0!


-------------------------
<?
function exitfp() {
    $fp = fopen("/usr/home/neil/public_html/test/output.txt","a");
    fputs($fp, connection_status());
    fclose($fp);
}
register_shutdown_function('exitfp');

if(connection_aborted() != true){print "0";}
set_time_limit(0);
ignore_user_abort(false);
$m = '10';
while(connection_aborted() != true and $a != $m){
    $c = 0;
    while($c != 4096){
        print connection_status();
        $c = $c + 1;
        $d = $d + 1;
        if($d == 128){
            $d = 0;
            print"<br>";
        }
        flush();
    }
    $a = $a + 1;
    sleep('5');
}

exitfp();

?>

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


You keep telling me this function is fixed, but surely the above code shuld have an output different to 0 if the user presses the stop button ?


Heres some version info from my server

FreeBSD admin.mghost.net 4.7-STABLE FreeBSD 4.7-STABLE #5: Sun Dec  1 00:39:59 GMT 2002     admin@admin.mghost.net:/usr/obj/usr/src/sys/ADMIN  i386


Apache/2.0.43 (Unix) PHP/4.3.0RC2
 [2002-12-08 03:17 UTC] sniper@php.net
For me your test script makes output.txt contain 1 when I press 'stop' button in my browser.

But I'm using Apache 1.3.27. And so should you as Apache2 is still beta quality.

 [2002-12-08 08:23 UTC] neil at mpfreescene dot com
Okay, I should report this to Apache then ?  This is a fault in there software ?
 [2002-12-08 10:46 UTC] sniper@php.net
This report describes another problem:

  http://bugs.php.net/bug.php?id=14542

So there is clearly some bug in there. But for aborts it definately works (on apache1) so you should report this
to apache folks too, would be nice to hear what they think of it.. :)

 [2002-12-08 17:01 UTC] neil at mpfreescene dot com
This may interest you :-

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=8996

Obviously if apaches log files are doing htat, then its completely the fault of apache 2 :-/
 [2002-12-13 04:04 UTC] neil at mpfreescene dot com
Okay, so we got the problem down to apache 2.x.  ANyway, I got time to install apache 1.3.27.

Now my system is running this :-

SERVER_SOFTWARE Apache/1.3.27 (Unix) PHP/4.3.0RC3 

And the problem still exists.

I run the exact same script as shown above, which yourselfs have verified should return a '1'.  The script is returning a 0, even if I press the STOP button.

I have not bothered to compile gzip into this apache installation, to ensure it is not that which causes a problem.


http://admin.mghost.net/~neil/test/ - script
http://admin.mghost.net/~neil/test/output.txt - output file
http://admin.mghost.net/~neil/test/test.cgi - standard perl diver script, to show details of my server.
 [2002-12-13 04:05 UTC] neil at mpfreescene dot com
ignore that, its working now, but it wasnt a minute ago.
 [2003-02-02 11:52 UTC] blahstyle at hotmail dot com
It's glad to meet the person who's suffering with same bug.

I have two sample codes that isn't run correctly.

First one:
<?
        ignore_user_abort (true);
        set_time_limit (0);
        for($i = 1; $i < 100; $i++) {
                $fp = fopen("conntest.out", "wt");
                fputs ($fp, $i.":".connection_aborted()."\n");
                echo "\n";
                flush ();
                fclose($fp);
                sleep(1);
        }
?>
It's supposed to stop at xx:0 when user press STOP button of browser, but it isn't. The number is continued until 100.

Second one:

<?php
function bye () {
	$fp = fopen ("./result.txt", "w");
	fwrite ($fp, "BYE CALLED AT ".date("YmdHi",time())."\r\n");
	fwrite ($fp, connection_aborted ());
	fclose ($fp);
	die();
}

register_shutdown_function ('bye');
set_time_limit ( 0 );
ignore_user_abort (true);

$fp = fopen ("./result.txt", "w");
while (!connection_aborted()) {
	echo "\n";
	flush ();
	sleep ( 1 );
}

?>

Registered Shutdown function won't work!

Neither of them worked correctly.

Apache 1.3.27 + PHP 4.3.0, Win32 / FreeBSD 4.6
PHP is running as a dynamic module for Apache.
 [2003-04-18 14:55 UTC] stank at stank dot stank
Same problem here.  If php can abort when the user aborts, why do you have to output to tell if the user has aborted?
 [2004-08-19 06:42 UTC] sneakin at semanticgap dot com
I tried using connection_aborted(), but I guess in 2 years time this bug hasn't been fixed. I'm using class.jabber.php, and I'm still waiting for it to disconnect from a page that got stopped. I'm using PHP 4.3.2.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 00:01:30 2024 UTC