Can PHP Power Comet Real-Time Messaging?
One may consider implementing real-time chat using PHP as the backend. However, a common critique cast a shadow over this idea:
"PHP is reportedly a poor choice for Comet, as it requires maintaining persistent connections with each browser client. Utilizing mod_php entails tying up an Apache child exclusively for each client, rendering the solution unscalable."
Delving Deeper into the Issue
To address this concern, let's examine the underlying challenges:
Apache's Thread Management
Every Apache request engages a separate worker thread until its completion. Comet requests, known for their long durations, can monopolize these threads.
PHP's Concurrent Execution Limitations
Even if Apache's thread allocation is resolved, PHP's nature requires a unique thread per request. As a result, FastCGI fails to remedy the situation.
Continuations: Beyond PHP's Reach
Continuations, which enable the resumption of comet requests upon event triggers, are not inherently supported by PHP.
Possible Solutions
Despite these obstacles, workarounds exist:
Caveats
These solutions come with caveats. The event MPM may not offer significant improvements, and load balancing introduces additional complexity to the architecture.
The above is the detailed content of Can PHP Effectively Handle Comet-Based Real-Time Messaging?. For more information, please follow other related articles on the PHP Chinese website!