What is the role of Middleware in a modern PHP framework, and how does it sit between the request and the response?

Last updated 15 June 2026

  • Middleware wraps request handling like onion layers. Each layer sees the request on the way in and the response on the way out (standardized by PSR-15's MiddlewareInterface::process()).

  • It handles cross-cutting concerns such as authentication, CORS, logging, sessions and rate limiting.

  • Each layer either calls $handler->handle($request) to continue and may modify the response, or short-circuits by returning early (e.g. a 401).

  • https://dev.to/testmuai/190-top-laravel-interview-questions-2023-3nog
  • https://www.geeksforgeeks.org/php/php-interview-questions-and-answers/
All PHP interview questions