🐘 PHP Advanced

What is the PHP Event Loop concept with ReactPHP?

Why Interviewers Ask This

This is a differentiating question used for senior and lead roles. Interviewers want to see if you can explain not just what happens, but why — and what the trade-offs are in different approaches.

Answer

Traditional PHP-FPM handles one request per process — it is synchronous and blocking. ReactPHP's event loop enables a single PHP process to handle thousands of concurrent I/O operations asynchronously. The event loop monitors file descriptors, timers, and signals. When an I/O operation (network request, file read) is ready, the loop dispatches the registered callback — no blocking. Key ReactPHP components: EventLoop (the core), Socket (async TCP/UDP), Http (async HTTP server), ChildProcess (spawn processes), Promise (deferred values). Example: a ReactPHP HTTP server handles 10,000 concurrent connections in a single PHP process, while PHP-FPM would need 10,000 worker processes. ReactPHP is ideal for WebSocket servers, API gateways, and long-running background services where PHP-FPM's process-per-request model is too expensive.

Common Mistake

A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.