The connection_aborted() function does not work on my system.
I checked it with the folowing test:

<?
ignore_user_abort(1);
while(!connection_status()){
syslog(LOG_ALERT,"test");
usleep(500000);
}
syslog(LOG_ALERT,"END");
?>

And the script runs even if my browser is closed. I also tried register_shutdown_function which isn't working too.

i run php.4.0.3 on Apache 1.3.9 package from Dedian 2.2

Any Ideas how i could get them working, or how i could execute commands after closing the Browser?

Marc

    Hy,
    Your idea of using register_shut_down_function, wasn't bad at all. But you have to send something to the output (with echo, or print) for the shut_down function to be launched., otherwise your script will stay in that infinite loop.
    So use register_shutdown_function and echo.

      • [deleted]

      1. Doesn't ignore_user_abort(1) mean "please ignore the user's abort messages"?
      2. connection_aborted() activates when you click stop or close the browser while you are loading a page (php script), not after the page is loaded.

        yes ignore_user_abort does mean that, but the while loop runs as long as connection_abborted() is NOT true.
        So the while loop should end directly after the browser is closed or the stop button is pressed.
        After that it shoult execute the syslog(...,"END") and close itself.

        Marc

          I now tried something like this, but still the script run's forever in the while loop. I don't know why i didn't execute ignore_user_abort(1) in this example. could someone try this on his machine so that i know if it's an error in my php setup?

          Marc

          ---SCRIPT

          <?
          function myshutdown(){
          syslog(LOG_ALERT,"ENDFUNC");
          die("END");
          }

          echo "TEST";
          flush();
          register_shutdown_function("myshutdown");
          while(!connection_abborted){
          syslog(LOG_ALERT,"test");
          usleep(500000);
          }
          syslog(LOG_ALERT,"END");
          ?>

            • [deleted]

            connection_status() returns this:

            0 - NORMAL
            1 - ABORTED
            2 - TIMEOUT

            And you are checking for !connection_status(),
            so the NORMAL state evals to true.
            And as you are ignoring the users' aborts, it'll stay that way not matter that the browser does.

              That's not true.

              From: http://www.php.net/manual/en/features.connection-handling.php

              One thing to note is that both the ABORTED and the TIMEOUT states can be active at the same time. This is possible if you tell PHP to ignore user aborts. PHP will still note the fact that a user may have broken the connection, but the script will keep running. If it then hits the time limit it will be aborted and your shutdown function, if any, will be called. At this point you will find that connection_timeout() and connection_aborted() return TRUE. You can also check both states in a single call by using the connection_status(). This function returns a bitfield of the active states. So, if both states are active it would return 3, for example.

              The connection_aborted, conection_status are IMO especially for checking if ignore_user_abort is 1.

              As a little note I only inserted connection_status because connection_abort wasn't working. I yust forget to cahnge it back before posting it here.

              But maybe you know another way, so I'll explain what i need.

              I have an endless loop (or one that end's when the connection is closed) and want that this loop stop's and executes another command when the connection is closed by closing the browser of hitting the stop button.

              Marc

                Write a Reply...