|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
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(); ?>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.0RC2It'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.