Asynchronous Requests (on the server)
Posted: Fri May 02, 2008 12:52 pm
Dear All,
I'm new to this forum and I hope i'm writing in the right place.
Before you move me to a newbie forum, please note, this is not an AJAX question, what i'm interested about is Aynchronous request handling on the server side of PHP.
I want to make an app, quite similar to a chat system, in which the client will poll the server for news CONSTANTLY. The obvious way is to have the client poll every "x" seconds, which depending on the value of "x" will either get unresponsive on the client, or will kill the server.
A method I found, and have successfully implemented in .Net is not responding to each poll with "nothing new here" every time, but instead keeping the client request (not responding at all), and only responding when there's effectively something to tell (or when something like 30 seconds go by, so as not to time out on the client)
Now, the "normal" way of doing this implies that while the server is not responding, it keeps a web server thread busy, which implies that i need 2000 threads if I have 2000 people on the client. (If I'm understanding this correctly)
.Net gave me this magical solution called "asynchronous handlers" that let me release the thread, but not reply to the client, and then only reply when i have to, using another thread (and a magical object I keep a reference to, which is the user's request). This lets me scale wildly while i still have only very few threads on the server.
Is it possible to do something like that in PHP?
Or at least, in ANY *nix environment at all (taking into account the fact that i'd like to avoid having to write my own web server)? (I can learn other languages like Python if I have to)
Has anyone heard of an approach like this that I can use?
Thank you very much in advance for your help
Daniel Magliola
I'm new to this forum and I hope i'm writing in the right place.
Before you move me to a newbie forum, please note, this is not an AJAX question, what i'm interested about is Aynchronous request handling on the server side of PHP.
I want to make an app, quite similar to a chat system, in which the client will poll the server for news CONSTANTLY. The obvious way is to have the client poll every "x" seconds, which depending on the value of "x" will either get unresponsive on the client, or will kill the server.
A method I found, and have successfully implemented in .Net is not responding to each poll with "nothing new here" every time, but instead keeping the client request (not responding at all), and only responding when there's effectively something to tell (or when something like 30 seconds go by, so as not to time out on the client)
Now, the "normal" way of doing this implies that while the server is not responding, it keeps a web server thread busy, which implies that i need 2000 threads if I have 2000 people on the client. (If I'm understanding this correctly)
.Net gave me this magical solution called "asynchronous handlers" that let me release the thread, but not reply to the client, and then only reply when i have to, using another thread (and a magical object I keep a reference to, which is the user's request). This lets me scale wildly while i still have only very few threads on the server.
Is it possible to do something like that in PHP?
Or at least, in ANY *nix environment at all (taking into account the fact that i'd like to avoid having to write my own web server)? (I can learn other languages like Python if I have to)
Has anyone heard of an approach like this that I can use?
Thank you very much in advance for your help
Daniel Magliola