mercredi 1 juillet 2015

ajax queries still waiting after window close

I have webpage that has an ajax call that gets data from a php script.

ajaxRequest = new XMLHttpRequest();
ajaxRequest.open("GET", "submit.php?id=" + id, true);
ajaxRequest.send(null);

Inside the submit.php I wait for a binary to finish and create an outfile.

while(1){
    if(is_file($OUTFILEPATH)){
        break;
    }else{
        sleep(60);
    }
}

The problem is that if the user closes the browser window, the ajax call and corresponding httpd are not aborted.

And if the user refreshes the webpage multiple times, I end up having hundreds of httpd processes all waiting for the the same outfile to be created.

Apache Server Status
115 requests currently being processed, 5 idle workers

WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW_W____........
................................................................
................................................................

Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,

Aucun commentaire:

Enregistrer un commentaire