What is PHP async programming with ReactPHP or Amp?
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 is synchronous and blocking — each request runs in its own process, sequential I/O blocks execution. ReactPHP and Amp are event loop libraries that enable non-blocking I/O in PHP, similar to Node.js. An event loop watches for I/O events (socket ready, timer fired) and dispatches callbacks. ReactPHP uses Promises for async operations. Amp (v3) uses PHP 8.1 Fibers, allowing async code to be written in a synchronous style with $value = await($promise);. Use cases: HTTP servers handling thousands of concurrent connections, WebSocket servers, background job processors, and any I/O-heavy long-running PHP process where spawning a new process per connection is too expensive. Traditional PHP (FPM) is still better for most web apps due to simpler deployment.
Pro Tip
This topic has PHP-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.
Previous
What is Command Query Responsibility Segregation (CQRS) in PHP?
Next
What is Domain-Driven Design (DDD) in PHP?