Hi,
Is anyone working on a suspendable request support in PHP when used as a
module in Apache?
Suspendable requests are great for supporting Server Push technology, but
are currently only supported in Jetty and Tomcat.
The API would be extremely simple, for example:
suspend(string request_id, int timeout);
- this would end the current request but keep the client connection open up
to "timeout" seconds.
resume(string request_id);
- this would resume a suspended request by starting a new PHP request but
reusing the same client connection that was previously suspended
I think there is enough support in Apache 2 APR to make this possible. What
do you guys think?
- Rusty
Hi,
Is anyone working on a suspendable request support in PHP when used as a
module in Apache?Suspendable requests are great for supporting Server Push technology, but
are currently only supported in Jetty and Tomcat.The API would be extremely simple, for example:
suspend(string request_id, int timeout);
- this would end the current request but keep the client connection open up
to "timeout" seconds.resume(string request_id);
- this would resume a suspended request by starting a new PHP request but
reusing the same client connection that was previously suspendedI think there is enough support in Apache 2 APR to make this possible. What
do you guys think?
Can you provide some scenario, when this is useful?
--
Alexey Zakhlestin
http://blog.milkfarmsoft.com/
Can you provide some scenario, when this is useful?
Server Push is an http hack that enables the server to send a message to the
client immediately, without the need for a client to poll the server.
Basically, the client makes an XMLHTTP request to which the server doesn't
answer immediately, but only answers when an event occurs, or when it times
out (then the client re-opens the connection).
Examples:
- Chat rooms. It's nice to post new messages to the clients as soon as they
become available. - A Mail client can inform the user of new mail as soon as it arrives. (as
does gmail) - Long searches can return as soon as data is available, without polling
the server every n seconds.
More details here:
http://code.google.com/p/google-web-toolkit-incubator/wiki/ServerPushFAQ
Now., the problem is that valuable server resources are taken up by these
lingering connections:
- A TCP Connection. The practical limit on these is ~100,000. Which is
pretty high. I could live with that. - The Server Thread. The limit is very low, on the order of ~100. That's
why it is very important to be able to release the server thread.
Hope this helps,
- Rustam
On Sun, Sep 14, 2008 at 5:33 PM, Rustam Abdullaev rustamabd@gmail.com
wrote:Hi,
Is anyone working on a suspendable request support in PHP when used as a
module in Apache?Suspendable requests are great for supporting Server Push technology, but
are currently only supported in Jetty and Tomcat.The API would be extremely simple, for example:
suspend(string request_id, int timeout);
- this would end the current request but keep the client connection open
up
to "timeout" seconds.resume(string request_id);
- this would resume a suspended request by starting a new PHP request but
reusing the same client connection that was previously suspended
Two ideas:
First is, for a rough approach that works today: you can emulate this by
polling from the suspended process by sleeping for, say, 400ms and checking
a shared value for a flag whether to resume.
Second and most important though, Apache isn't architected to handle long
running processes inside a request, as it typically uses a limited pool of
threads/processes to serve requests, if enough requests in the pool are held
up suspended, it would prove heavily detrimental to the server performance
(this is why "push" technologies like Comet are not recommended on Apache).
I would possibly suggest the requests communicating with (for example), long
running background processes running from shell from that purpose, using
standard interprocess communication like unix sockets.
Second and most important though, Apache isn't architected to handle long
running processes inside a request, as it typically uses a limited pool of
Not true.. Tomcat supports comet, and it runs on APR. Yes, the thread pool
is small, but there is always a solution. The idea is to return the thread
back to Apache's thread pool while waiting for an event:
http://tomcat.apache.org/tomcat-6.0-doc/aio.html
None of the workarounds (like polling, locking, etc) will work, the only
real fix is to release the thread back to the pool. Or write a standalone
process, but then it will need its own IP since running on a different port
is known to cause problems with transparent proxies.
Anyway, I'm positive that its doable.. Those Java guys have it already :)
Second and most important though, Apache isn't architected to handle long
running processes inside a request, as it typically uses a limited pool ofNot true.. Tomcat supports comet, and it runs on APR. Yes, the thread pool
is small, but there is always a solution. The idea is to return the thread
back to Apache's thread pool while waiting for an event:
http://tomcat.apache.org/tomcat-6.0-doc/aio.html
Then convince the Apache developers to implement the feature in Apache
httpd...
Anyway, I'm positive that its doable.. Those Java guys have it already :)
... if you find a good way: feel free to send a patch :-)
johannes
Not true.. Tomcat supports comet, and it runs on APR. Yes, the thread pool
is small, but there is always a solution. The idea is to return the thread
back to Apache's thread pool while waiting for an event:
http://tomcat.apache.org/tomcat-6.0-doc/aio.htmlThen convince the Apache developers to implement the feature in Apache
httpd...
They are not interested. If you want to have comet apps and stream
bits of data fast for email (gmail) or stockprices in the middle of
your text (marketwatch) then you have to go use other tools. If you
must use PHP, you will have to write your own long lasting web
server in PHP -- but note that PHP was not designed for that. Neither
was apache. There is a reason why all the comet stuff is written in
other languages and use other web servers. Best bet -- use another
tool stack. Typically you have have it call into other code as needed
(like PHP) for things like authentication or data collection, and
since the usage pattern is different, you probably want it on a
separate cluster anyway.
http://cometdaily.com/ is a better channel to gather some info.
Rustam Abdullaev wrote:
Hi,
Is anyone working on a suspendable request support in PHP when used as a
module in Apache?
The 'Event' mpm should be there already, IIRC.