February 06, 2010 05:00AM
Hi all!

I am optimizing a few of the PHP scripts by:
- doing all that generates output to browser
- closing connection to browser
- doing some more processing

The processing bit cannot be avoided, but the speed of execution (from visitors' point of view) is awesome this way. The problem is that we have tried migrating the script to NginX + FastCGI (it works on Apache + mod_php) but it doesn't close the connection anymore, it keeps it open until the end... Which makes scripts slow again.

I am using Content-Length to allow server to figure out that all content was already generated. This is the test case:
[code]
<?
header("Connection: close"); // not sure we need this one
header("Content-Encoding: none");
ignore_user_abort(true);
ob_start();

echo ('Lets output something.');

// output Content-Length and flush buffers:
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush();
flush();

// ****************
// do some heavy processing here:
sleep(5);

function postproc() {
flush();
sleep(5);
}
register_shutdown_function('postproc');
?>
[/code]

The browser shows this page immediately in Apache+mod_php but it waits for 10 seconds in NginX + FastCGI.

I am a bit stuck here and would appreciate some help... Is this a problem with FastCGI? Is there another way to do it?

Thanks!
Subject Author Posted

FastCGI PHP - unable to prematurely close connection to browser

cactus February 06, 2010 05:00AM

Re: FastCGI PHP - unable to prematurely close connection to browser

Hoang Hoang February 06, 2010 10:32AM

Re: FastCGI PHP - unable to prematurely close connection to browser

cactus February 07, 2010 06:30AM

Re: FastCGI PHP - unable to prematurely close connection to browser

Rob Schultz February 07, 2010 12:08PM

Re: FastCGI PHP - unable to prematurely close connection to browser

Reinis Rozitis February 08, 2010 06:42AM

Re: FastCGI PHP - unable to prematurely close connection to browser

cactus February 14, 2010 09:28AM

Re: FastCGI PHP - unable to prematurely close connection to browser

cactus February 07, 2010 01:30PM

Re: FastCGI PHP - unable to prematurely close connection to browser

Rob Schultz February 07, 2010 01:54PM

Re: FastCGI PHP - unable to prematurely close connection to browser

cactus February 07, 2010 02:48PM

Re: FastCGI PHP - unable to prematurely close connection to browser

Tobia Conforto February 08, 2010 04:32AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 119
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready