Long Polling with PHP on Apache

时光总嘲笑我的痴心妄想 提交于 2019-12-18 16:32:13

问题


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?


回答1:


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.




回答2:


I don't think there is a solution. You can't distinguish a polling request from a normal request. Only avoid Apache that could help (e.g. running nginx on 80, forward all requests to Apache on 81, except polling requests).

I also don't think you have a problem. Nginx or other server is not much more efficient than Apache. Polling is a PHP request, Apache with mod_php is less or more a good choice. Nginx won't use less resource than Apache in serving PHP.



来源:https://stackoverflow.com/questions/9730857/long-polling-with-php-on-apache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!