Keep-Alive problem

This is a discussion on Keep-Alive problem within the PHP General forums, part of the PHP Programming Forums category; Hy, I've a problem with a keep-alive connection. I've describe it in http://bugs.php.net/bug....


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-23-2007
Julien Allali
 
Posts: n/a
Default Keep-Alive problem

Hy,
I've a problem with a keep-alive connection. I've describe it in
http://bugs.php.net/bug.php?id=40895 but it seems to not
be a bug.

The problem is simple: My browser calls the same page twice
with a keep-alive connection.

The first time, I answer quickly but i have some stuff to do
so I use the "Content-Length" to indicate to the browser that
the response is done:

ignore_user_abort(true);
$msg="toto";
header("Content-Length: ".strlen($msg));
echo $msg;
flush();
.... some long time stuff here


The browser clearly understand the Content-Length because
it makes the second Http Request before the end of the first call
(after the read of the strlen($msg) bytes).

Then, the second call is blocked until the first call is entirely done.

Now, If I explicitly ask the browser for closing the connection:

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();


all work fine.

To my question is really simple:
How could I tell to php to notify apache that the response is done so
it will treat the second response hence if the first call is not finished?

Note:
*I look for something like closing standard output but I didn't find a
solution
*I'm not interested in solution like putting the job into a database
table and
having a cron process.
*I think there is no php functions/way to do so, so isn't it a bug?
(missing important
feature).


Thx
Julien Allali.

--
Julien Allali
LaBRI Modeles et Algorithmes pour la Bioinformatique et la Visualisation
351, cours de la Libération
33405 Talence Cedex 33405
France

email: julien.allali@labri.fr
phone: +33(0)5 40 00 36 11
mobil: +33(0)6 10 46 48 43
homepage: http://igm.univ-mlv.fr/~allali/
Reply With Quote
  #2 (permalink)  
Old 03-23-2007
Jon Anderson
 
Posts: n/a
Default Re: [PHP] Keep-Alive problem

Julien Allali wrote:
> Then, the second call is blocked until the first call is entirely done.
>
> Now, If I explicitly ask the browser for closing the connection:
> <snip>
> all work fine.

I believe the reason for this is specifically because of the connection
to one apache process. Since apache prefork just uses one
single-threaded (forked) process to handle each connection, when you
issue a connection: keep-alive header, that one process is busy handling
the first request, so the second request just sits and waits for the
first to complete. If you issue a connection: close header, it works
simply because your first request hits one apache process (which will be
busy for some time), and your second request hits an entirely different
apache process.

For other apache threading models, replace "process" above with
"thread". Same idea.
> To my question is really simple:
> How could I tell to php to notify apache that the response is done so
> it will treat the second response hence if the first call is not
> finished?

It's one process (or thread). AFAIK, it can't do that. You're asking one
thread of execution to understand (automagically) that it has to pause
execution, handle the next request, then resume the first.

Using "connection: close" does almost exactly what you need, with the
unfortunate side effect of having to re-establish a connection...Why not
just stick with that? Alternately, you might be able to spawn off
another command-line PHP process by calling system() or similar.
> *I think there is no php functions/way to do so, so isn't it a bug?
> (missing important
> feature).

IMO, it's expected behavior.

jon
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:58 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0