Web Framework Internals interview question · Most asked

Walk through the Laravel request lifecycle and say where you would add code that must run on every request.

Summary

public/index.php loads the autoloader and app; the HTTP kernel bootstraps (environment, configuration, error handling, facades) and registers then boots all service providers; global middleware runs; the router matches a route and applies its middleware group and route middleware; the controller runs; the response passes back through middleware in reverse and is sent; terminable middleware runs afterwards. Code for every request goes in global middleware; wiring goes in service providers, kept cheap.

Longer Answer

Under PHP-FPM, providers boot on every request, so queries or HTTP calls in boot() slow down everything; under Octane they boot once per worker, so request data must not be captured in singletons.

Key Points

  • Bootstrap → providers register/boot → middleware → router → controller.
  • Response back through middleware, then terminate.
  • Every-request code in global middleware.
  • Keep providers cheap.

Deep dive: Request Lifecycle: The Laravel Request Lifecycle

Explanation

What interviewers look for

Correct order and awareness of provider cost.

More most-asked Web Framework Internals questions

← All Web Framework Internals questions