Most applications in PHP, in their essence, are built on the principle of "born to die." Those. To process each new request, a new instance of the application must be created.
Even the use of Fast CGI (PHP-FPM) does not remove this limitation. Its main function is to run the PHP interpreter as a daemon, so that it does not need to be initialized every time. The application continues to be initialized every time you need to respond to the request.
What happens in the rails: The application is one large class, which, among other things, implements the Rack-interface . Thanks to this architecture, it can be permanently loaded into memory. The task of backend servers (such as Unicorn or Puma) is to keep this class in its memory, pass request parameters to it and return a response.
In short (and roughly):
- PHP-FPM immediately creates an interpreter process that executes php scripts when necessary.
- Unicorn - immediately loads the entire application into memory and sends it requests for processing.
Theoretically, nothing prevents to write a rack interface for an application on PHP and run it through Unicorn. Just as nothing prevents the use of CGI, including Fast, for launching rail applications (by the way, it seems there were FastCGI implementations for Ruby). But you need to understand that:
- Heavy rails. Downloading the entire application with each request can be superimposed;
- Most likely, you will have to add a little frame application, so that it works correctly.