Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long Polling with PHP on Apache

Hopefully I can explain this well enough. I am working on creating a PHP library to handle ajax requests through PHP in an object oriented manner. I am currently pondering a good way to implement a long polling solution but am curious about something.

Apache doesn't handle keeping multiple connections open very well. The thread-per-request model makes Apache highly inefficient for long polling. Using server's such as nginx and lighttpd handle these threads much better so in the library, I plan on implementing different functions optimized to the specific servers available from a single function call. In the case of Apache, which happens to hold an enormous market share for PHP applications, I need a better solution.

Is there a way to place an incoming request on hold/pause and continue processing other requests until I am ready to reactivate it?

I'm not sure if that makes sense or if I am even on the right track. What is a possible solution that SO recommends for long polling in PHP on an Apache server?

like image 875
Jeremy Harris Avatar asked Mar 16 '12 02:03

Jeremy Harris


1 Answers

This sounds like continuations. You can definitely not do this in PHP, in any elegant way. If you want to do this, your best chance would be to save the current state, and write the code in such a way that you can resume from where you left off when you load the state.

like image 114
rid Avatar answered Oct 24 '22 10:10

rid