Fastcgi_finish_request creates a hangup when an open session exists

I have a client side that sends a request that requires a long processing time, the client sends the request in ajax. After the request is accepted on the server, the client is redirected to another page, this is done using fastcgi_finish_request (I run 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" } }); 

Ajax is dispatched, and a successful callback causes a redirect to next_page.php, as expected.

But then the page stops, and I get no service until the dream ends. It looks like my connection is waiting for the completion of the same php-fpm process

I am running nginx with php-fpm, any idea why this is happening?

EDIT :

After much research, I found that the reason for this behavior is that I have an active session (from the facebook SDK file) when I destroy a 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 think of this solution?

Should I do something different from session_destroy()

EDIT:

after Lachlan Pease comment, I switched session_destroy to session_write_close

+4
source share
2 answers

The problem was the existence of the session, see "Editing in Questions" for more details.

+1
source

I also encounter this problem, I register a function to run register_shutdown_function, and the function starts with fastcgi_finish_request, while I found that the scripts after fastcgi_finish_request () still block the user page, and put session_destroy (); ahead of fastcgi_finish_request (); worked and the user page no longer blocks.

0
source

All Articles