Yii 2: detailed description of HTTP request lifecycle
From Request to Response: How Yii 2 Handles HTTP Requests

Optimizing Query Processing in Yii 2: Understanding the Lifecycle



Request lifecycle description in Yii 2

Each time when a Yii application handles a request, it undergoes a similar workflow.

  1. A user makes a request to the entry script web/index.php.
  2. The entry script loads the application configuration and creates an application instance to handle the request.
  3. The application resolves the requested route with the help of the request application component.
  4. The application creates a controller instance to handle the request.
  5. The controller creates an action instance and performs the filters for the action.
  6. If any filter fails, the action is cancelled.
  7. If all filters pass, the action is executed.
  8. The action loads a data model, possibly from a database.
  9. The action renders a view, providing it with the data model.
  10. The rendered result is returned to the response application component.
  11. The response component sends the rendered result to the user's browser.

Illustration of request lifecycle in Yii 2

The following diagram shows how an application handles a request.

How Yii 2 handles requests: from routing to rendering

In this section, we will describe in detail how some of these steps work.

Старт! MoonВase — A Hot Start on the Internet
Старт! MoonВase — A Hot Start on the Internet
Старт! Menu