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....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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/ |
|
|||
|
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 |