Recognizing the tradeoffs described above, several projects have emerged in the PHP ecosystem over the past few years that implement different design philosophies to reduce both response time and server costs, while finding ways to mitigate additional development complexity.
The first tradeoff typically made is the switch from ‘shared nothing’ single-threaded request handlers to PHP application servers with long-lived worker threads. In this scenario, bootstrapping happens once when the worker thread is initially started. The worker thread then processes multiple requests passed to it by the application server, and remains alive for the lifetime of the application server.
By reducing or eliminating the bootstrapping phase on every request, we are able to deliver a significant reduction in request response times, often doubling the server’s request throughput.
Of course, this comes with tradeoffs regarding application state and memory leakage. Most of the existing code and libraries were written with the assumption that the state would be destroyed at the end of the request. While most code will likely continue to work fine, there is a chance that some classes may retain state between requests.
Take for example a class object that accumulates status messages generated during a request. If this class object is not adequately re-initialized prior to the next request, it could lead to status messages intended for one user being shown to another.
There is also potential for memory leakage - a class object that collects data or information may again not be sufficiently flushed or reinitialized between requests, and grow in memory consumption as each request adds more data until an out of memory error causes the worker thread to die.