Faqts : Business : Programming : Shopping For You : PHP : Common Problems : Tips and Tricks

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 10 people (60%) answered Yes
Recently 2 of 4 people (50%) answered Yes

Entry

How can I tell if the user has aborted the download?
How can I force a script to execute completely even if the user aborts?

Aug 23rd, 2009 00:29
johnny deep, Nathan Wallace, Rasmus Lerdorf


Add connection_status() function.  This returns the raw bitfield which 
indicates whether the script terminated due to a user abort, a timeout
or normally.  Note that if ignore_user_abort is enabled, then both the 
timeout state and the user abort state can be active

    http://www.php.net/manual/function.connection-status.php3

Add connection_timeout() function.  This one can be called in a shutdown
function to tell you if you got there because of a timeout

    http://www.php.net/manual/function.connection-timeout.php3

Add ignore_user_abort() function and .ini/.conf directive of same name

    http://www.php.net/manual/function.ignore-user-abort.php3

Fix connection abort detection code - It should now work reliably with 
Apache.  Also added a user-level connection_aborted() function designed
to let people check whether the user aborted the connection in a
user-level shutdown function.
http://www.webs4soft.com/
http://www.webs4soft.com/index.htm
http://www.webs4soft.com/index.html
http://www.webs4soft.com/About-us.htm
http://www.webs4soft.com/SEO-Services-India.htm
http://www.webs4soft.com/Web-Design-India.htm
http://www.webs4soft.com/Web-Development-India.htm
http://www.webs4soft.com/Feedback.htm
http://www.webs4soft.com/Contact-us.htm
http://www.webs4soft.com/web-hosting-india.htm
http://www.webs4soft.com/multimedia-webdesign.htm
http://www.webs4soft.com/graphic-design.htm
http://www.webs4soft.com/logo-design-india.htm
http://www.webs4soft.com/Internet-Marketing.htm
http://www.webs4soft.com/software-development-india.htm
http://www.webs4soft.com/print-design.htm
http://www.webs4soft.com/Professional-Logo-Designs.htm
http://www.webs4soft.com/Corporate-Logo-Design.htm
http://www.webs4soft.com/Company-Logo-Design.htm
http://www.webs4soft.com/Ad-Design.htm
http://www.webs4soft.com/flyer-design.htm
http://www.webs4soft.com/Illustration.htm
http://www.webs4soft.com/brochure-design.htm
http://www.webs4soft.com/add-url-form.php
http://www.webs4soft.com/Links.htm
http://www.webs4soft.com/Links1.htm
http://www.webs4soft.com/Links2.htm
http://www.webs4soft.com/Links3.htm
http://www.webs4soft.com/Links4.htm
http://www.webs4soft.com/Links5.htm
http://www.webs4soft.com/web-promotion.htm
http://www.webs4soft.com/Dynamic-Website-Design.htm
http://www.webs4soft.com/Book-Cover-Design.htm
http://www.webs4soft.com/High-End-Graphic-Design.htm
http://www.webs4soft.com/Book-Layout-Design.htm	
http://www.webs4soft.com/newsletter-design.htm
http://www.webs4soft.com/Photo-Manipulation.htm
http://www.webs4soft.com/Photo-Restoration.htm
http://www.webs4soft.com/E-Card-Design.htm
http://www.webs4soft.com/search-engine-ranking.htm
http://www.webs4soft.com/search-engine-submission.htm
    http://www.php.net/manual/function.connection-aborted.php3

Here is the test script as used by Rasmus when writing the functions:

<?
    set_time_limit(5);
    ignore_user_abort(0);
    register_shutdown_function("done");
    function done() {
        global $i, $fp;

        fputs($fp,"i reached $i\n");
        if(connection_aborted())
            fputs($fp,"** the connection was aborted **\n");
        fclose($fp);
        echo "all done\n";
    }

    $fp = fopen("/tmp/done","w");
    for($i=0; $i<7; $i++) {
        fputs($fp,"i is $i\n");
        for($j=0;$j<1000;$j++) $a=sqrt($j);
        sleep(1);
        echo "$i
................................................................................<br>";
        flush();
    }
    exit;
?>

This should give you some ideas.