#40895 [NEW]: Problem for ending http_requests with Keep-Alive

From: Date: Thu, 22 Mar 2007 17:21:16 +0000
Subject: #40895 [NEW]: Problem for ending http_requests with Keep-Alive
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-110694@lists.php.net to get a copy of this message
From: allali at labri dot fr Operating system: Linux PHP version: 5.2.1 PHP Bug Type: Output Control Bug description: Problem for ending http_requests with Keep-Alive Description: ------------ The problem is that I have a script which is called twice by the same brother using a Http connection with the Keep Alive attibute. For the first call: I notify the end of the answer as follow: =========================================== ignore_user_abort(true); $msg="toto"; header("Content-Length: ".strlen($msg)); echo $msg; flush(); ... some long time stuff here= =========================================== the browser read the answer and then I ask again for the same page using the same tcp connection (Keep-alive). In the second call, the output is blocked until the first call process is dead. Thus its execution is suspended until the "long time stuff" is done. (I see the http request using tcpdump). If I put the following for the first call: ==================================================== header("Cache-Control: no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Connection: close"); $msg="toto"; header("Content-Length: ".strlen($msg)); echo $msg; flush(); ===================================================== then all work fine except that the connection is effectively closed by the browser and then re-open which implies a great lost of performances. Also I did not find any mechanism (bug?) in php to indicate that the response is done. (like http_close or fclose(STDOUT) // STDOUT doesn't exists...). Maybe, php is suppose to guess that using the Content-Length (bug?). Perhaps it is apache which is waiting for the end of the process or the closing of the standard process output. Finally, I think this become critical in AJAX aplications. Thx J.A. Reproduce code: --------------- <? // hello.php if (isset($_GET["a"])==false){ ignore_user_abort(true); $msg="hello"; header("Content-Length: ".strlen($msg)); if (isset($_GET["close"])){ header("Cache-Control: no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Connection: close"); } echo $msg; flush(); sleep(20); } else{ echo "world!"; } ?> Expected result: ---------------- just call the script twice: hello.php => hello hello.php?a => world! immediately Actual result: -------------- just call the script twice: hello.php => hello hello.php?a => world! after 20 seconds. -- Edit bug report at http://bugs.php.net/?id=40895&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40895&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40895&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40895&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=40895&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=40895&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=40895&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=40895&r=needscript Try newer version: http://bugs.php.net/fix.php?id=40895&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=40895&r=support Expected behavior: http://bugs.php.net/fix.php?id=40895&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=40895&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=40895&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=40895&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40895&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=40895&r=dst IIS Stability: http://bugs.php.net/fix.php?id=40895&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=40895&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=40895&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=40895&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=40895&r=mysqlcfg

« previous php.bugs (#110694) next »