Change record status: 
Project: 
Introduced in branch: 
11.x
Introduced in version: 
11.5.0
Description: 

Drupal's service container can now be compiled and stored as a PHP class file using Symfony's PhpDumper. The resulting class is stored via PhpStorage and benefits from OPcache, which can reduce container build time on warm requests. New Drupal installations default to this mode. Existing sites that upgrade continue to use the legacy PHP array-based container for backward compatibility.

What to do

To switch to the compiled PHP container, add the following line to your settings.php:

  $settings['container_base_class'] = \Drupal\Core\DependencyInjection\PhpContainer::class;

New Drupal installations include this line in default.settings.php by default. Sites upgrading from an earlier version will not have it and continue to use the PHP array-based container unless they add it manually.

The container_base_class setting controls which container implementation is used at runtime:

  • \Drupal\Core\DependencyInjection\PhpContainer — uses Symfony's PhpDumper to compile the container into a PHP class file stored in PhpStorage (typically sites/default/files/php/service_container/). The file is included on each request and benefits from OPcache.
  • \Drupal\Core\DependencyInjection\Container (or unset) — legacy mode using the PHP array-based container serialised to the cache.container cache bin. This remains the default for sites that do not set container_base_class in order to preserve backward compatibility.

Notes

  • The compiled PHP container file is stored in sites/default/files/php/service_container/ (or wherever your php PhpStorage directory is configured).
  • When clearing caches (drush cr or the UI cache rebuild), the old container file is deleted if the container changes..
Impacts: 
Site builders, administrators, editors
Site templates, recipes and distribution developers