Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fastcgi_finish_request creates hung connection when open session exists

I have a client side that sends a request that need long processing time, the client send the request in ajax. Once the request is accepted on the Server the client redirects to another page, this is accomplished by fastcgi_finish_request (I am running php-fpm)

LongWork.php:

<?php
    fastcgi_finish_request(); 
    sleep(1000); //Simulate long computation time
?>

client.js:

$.ajax({
    url: "...",
    data: {},
    success: function() {
        top.location.href="next_page.php" 
    }
});

The ajax gets sent and success callback causes redirection to next_page.php as expected.

But then the page halts and I do not get any service until the sleep is finished. It looks like my connection is waiting for the same php-fpm process to finish

I am running nginx with php-fpm, any Idea why this happens?

EDIT:

After more investigation I found the cause to this behavior is that I have a active session (from facebook SDK), When I destroy the session on LongWork.php:

<?php
    session_destroy(); // Session was halting the client from accessing another page
    fastcgi_finish_request(); 
    sleep(1000); //Simulate long computation time
?>

Can you please reflect on this solution?

Should I do something different from session_destroy()

EDIT:

following Lachlan Pease comment, I have switched session_destroy with session_write_close

like image 275
ekeren Avatar asked Aug 01 '12 11:08

ekeren


1 Answers

The problem was with session existence, see Edits in Questions for more details

like image 125
ekeren Avatar answered Oct 20 '22 12:10

ekeren