Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

javadihugo's avatar

How often does Laravel bootstrap the application?

I thought Laravel would bootstrap the application once, keep it in memory and reuse it for every request. However, the lifecycle documentation (https://laravel.com/docs/11.x/lifecycle) makes it seem (to me) like the application is bootstrapped for every request!

Once the application has been bootstrapped and all service providers have been registered, the Request will be handed off to the router for dispatching.

The application instance is created, the service providers are registered, and the request is handed to the bootstrapped application. It's really that simple!

Is it just referring to the first request?

Does require_once in public/index.php make sure it only bootstraps the application once?

(require_once __DIR__.'/../bootstrap/app.php')
    ->handleRequest(Request::capture());
0 likes
3 replies
gych's avatar
gych
Best Answer
Level 29

Each request will pass via the index.php and therefore the application will be booted for each request. If you use Laravel Octane the application will be booted only once and kept in memory.

https://laravel.com/docs/11.x/octane

3 likes
LaryAI's avatar
Level 58

Laravel bootstraps the application for every HTTP request that comes into your server. This means that each time a user makes a request to your Laravel application, the entire application is bootstrapped, including the loading of service providers, configuration files, and routes.

The require_once in public/index.php does not ensure that the application is only bootstrapped once across multiple requests. Instead, it ensures that during the handling of a single request, the bootstrap/app.php file is only included once to prevent re-declaration errors.

Here's a simplified version of what happens during each request to a Laravel application:

  1. The web server (e.g., Apache or Nginx) receives the HTTP request and directs it to the public/index.php file of your Laravel application.
  2. The index.php file includes the bootstrap/app.php file, which creates the application instance.
  3. Service providers are registered and booted, configuration files are loaded, and the application is set up.
  4. The request is captured and handed to the application instance.
  5. The application routes the request to the appropriate controller and action.
  6. The response is generated and sent back to the user.

Here's the relevant part of the public/index.php file:

$app = require_once __DIR__.'/../bootstrap/app.php';

$request = Illuminate\Http\Request::capture();
$response = $app->handle($request);
$response->send();

$app->terminate($request, $response);

Each time a new HTTP request is made, this process starts from the beginning. Laravel does not keep the application in memory between requests in a standard PHP web server setup. This is different from how some application servers in other languages or frameworks might work, where the application is loaded into memory once and then persists across multiple requests.

If you want to reduce the cost of bootstrapping the application for each request, you could look into using PHP's opcache, which can cache the compiled PHP scripts in memory, or consider using Laravel Octane, which is designed to keep the application bootstrapped between requests by running on servers like Swoole or RoadRunner. However, these approaches have their own considerations and are not part of the standard Laravel setup.

2 likes

Please or to participate in this conversation.