# PHP Suspendable requests for Apache

- Thread: https://externals.io/message/40509
- Original archive: https://news-web.php.net/php.internals/40509
- Started by Rustam Abdullaev on 2008-09-14T13:33:12+00:00
- Messages: 8
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #40509 — Rustam Abdullaev — 2008-09-14T13:33:12+00:00

URL: https://externals.io/message/40509#40509

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

---

## #40510 — Alexey Zakhlestin — 2008-09-14T17:40:18+00:00

URL: https://externals.io/message/40509#40510 · In reply to: #40509

> 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?

Can you provide some scenario, when this is useful?

-- 
Alexey Zakhlestin
http://blog.milkfarmsoft.com/

---

## #40511 — Rustam Abdullaev — 2008-09-14T20:53:27+00:00

URL: https://externals.io/message/40509#40511 · In reply to: #40510

> 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:
1. Chat rooms. It's nice to post new messages to the clients as soon as they 
become available.
2. A Mail client can inform the user of new mail as soon as it arrives. (as 
does gmail)
3. 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:
1) A TCP Connection. The practical limit on these is ~100,000. Which is 
pretty high. I could live with that.
2) 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

---

## #40512 — Stan Vassilev | FM — 2008-09-14T20:56:13+00:00

URL: https://externals.io/message/40509#40512 · In reply to: #40510

> On Sun, Sep 14, 2008 at 5:33 PM, Rustam Abdullaev <rustamabd@gmail.com> 
> wrote:
> > […]

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.

---

## #40513 — Rustam Abdullaev — 2008-09-14T21:21:02+00:00

URL: https://externals.io/message/40509#40513 · In reply to: #40512

> 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 :)

---

## #40514 — johannes@php.net — 2008-09-14T23:03:42+00:00

URL: https://externals.io/message/40509#40514 · In reply to: #40513

> > […]
> 
> 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

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

---

## #40517 — William A. Rowe — 2008-09-15T07:58:31+00:00

URL: https://externals.io/message/40509#40517 · In reply to: #40509

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.

---

## #40695 — steve — 2008-09-26T03:48:42+00:00

URL: https://externals.io/message/40509#40695 · In reply to: #40514

> > […]
>
> Then 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.
