Jump to content

Asynchronous Requests (on the server)


dmagliola

Recommended Posts

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.

If this isn't the place to post, i'd really appreciate it if you can point me to the right place, and I apologize for the bother.

 

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

Link to comment
https://forums.phpfreaks.com/topic/103897-asynchronous-requests-on-the-server/
Share on other sites

Continuasly paging a MySQL Database will be hard on the system. I would personally think about looking into having your AJAX save data to a .txt document then using a javascript "Tick" have the file paged on a preset of what you want. Since there will only be data in UTF-8 format there will be limited bandwidth. mySQL would tend to use alot of BW if you keep paging the system. Im not really an AjAX coder myself so i wouldnt be able to give you any scripting examples.

Hi, thank you for your reply.

In fact, my problem is not really storing the data, or using MySQL at all.

Even if I store the data in .txt files, i'd still have the problem of releasing threads without actually responding to the client.

 

Any ideas on that part?

 

Thanks

Daniel

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.