php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40895 Problem for ending http_requests with Keep-Alive
Submitted: 2007-03-22 17:21 UTC Modified: 2007-03-22 18:05 UTC
From: allali at labri dot fr Assigned:
Status: Not a bug Package: Output Control
PHP Version: 5.2.1 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: allali at labri dot fr
New email:
PHP Version: OS:

 

 [2007-03-22 17:21 UTC] allali at labri dot fr
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-22 18:05 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 23:01:30 2024 UTC