Direkt zum Inhalt

Devbits

Kleine Code-Schnipsel aus unserem Alltag mit Drupal, PHP und DevOps: Problem, Lösung, Code.

01.09.2026 | Michael Ebert

Show the status report with Drush in your terminal

You want to show the status report inside your shell or terminal window instead of opening it in the browser, or if access to the status page is not possible for some reason.

drush core:requirements

Issue:

You want to show the status report inside your shell or terminal window instead of opening it in the browser, or if access to the status page is not possible for some reason.

Solution:

The Drush command in the snippet will show you the same output as the status report does (/admin/reports/status).

Read more in the official Drush documentation: https://www.drush.org/13.3.0/commands/core_requirements

19.03.2026 | Michael Ebert

Preview changed config before import/export with drush

You changed config and want to see the changes before it is exported to your config sync directory or you want to see what will be changed if you import changed config.

First, you could check if there are different states of your config between database and local file system.

drush config:status

There is an option `--diff` for the drush command that will print the changes first.

drush config:import --diff

This also works for config export.

drush config:export --diff

Issue:

You changed config and want to see the changes before it is exported to your config sync directory or you want to see what will be changed if you import changed config.

Solution:

There is an option for the drush commands that will print the changes first.

05.02.2026 | Michael Ebert

Make a database dump including data from an ignored table

You need a dump including the values of a datebase table that is ignored by your drush configuration.

drush sql:dump --structure-tables-list=cache,cachetags,'cache_*',history,'search_*',sessions,webprofiler

Issue:

You need a dump including the values of a datebase table that is ignored by your drush configuration.

Prerequisites:

You use drush in your setup and have a drush config file (e.g.: https://github.com/drush-ops/drush/blob/master/examples/example.drush.yml)  like this:

command:
  sql:
    dump:
      options:
        structure-tables-list:
          - cache
          - cachetags
          - 'cache_*'
          - history
          - 'search_*'
          - 'sessions'
          - 'watchdog'
          - 'webprofiler'

Solution:

This example overrides the settings for the ignored tables in your drush command to also get the data of the watchdog table.

13.11.2025 | Peter Majmesku

Drush 12+: Simplified Drush commands with PHP 8 attributes

Before Drush version 12 we needed to write a drush.services.yml file for having dependency injection. This leads to errors when we're installing new custom Drupal modules, because the modules *.services.yml file must be instantiated before the drush.services.yml file. That makes a workaround…

<?php

declare(strict_types=1);

namespace Drupal\nice_module\Drush\Commands;

use Drupal\Component\DependencyInjection\ContainerInterface;
use Drupal\nice_module\HelloWorldService;
use Drush\Attributes as CLI;
use Drush\Commands\DrushCommands;

/**
 * A Drush command class for saying "hello" to the world.
 */
final class HelloWorldCommands extends DrushCommands {

  public function __construct(
    private readonly HelloWorldService $helloWorldService,
  ) {
    parent::__construct();
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container): self {
    return new static($container->get('nice_module.hello_world_service'));
  }

  #[CLI\Command(name: 'nice_module:say-hello', aliases: ['smci'])]
  #[CLI\Argument(name: 'userName', description: 'The name of the user.')]
  public function sayHello(?string $userName = NULL): void {
    $this->helloWorldService->sayHello($userName, $this->output());
    $this->logger()->success('I said "hello" to the user.');
  }

}

Issue:

Before Drush version 12 we needed to write a drush.services.yml file for having dependency injection. This leads to errors when we're installing new custom Drupal modules, because the modules *.services.yml file must be instantiated before the drush.services.yml file. That makes a workaround necessary, where we do rename the drush.services.yml file, before we rebuild the cache for having the services from our modules *.services.yml instantiated. Also the old approach was not leveraging PHP attributes, which are available since PHP 8.

Solution:

The snippet file is meant to be located here: web/modules/custom/nice_module/src/Drush/Commands/HelloWorldCommands.php

By this approach there are no errors on new module installation, where we do have a modules `*.services.yml` and `drush.service.yml`. 

Via PHP attributes our command, argument, and usage descriptions are also validated with PHP. This makes our Drush commands less error prone. 

13.11.2025 | Nikolas Kopp

Clear APC & Opcache

You need to clear APC and Opcache, e.g. for debugging purposes.

<?php

apcu_clear_cache();
opcache_reset();

Issue:

You need to clear APC and Opcache, e.g. for debugging purposes.

Solution:

drush php:script clear_cache 

This snippet clears APCu and Opcache. Put it into the docroot. Execute from browser, not from CLI.

See the drush documentation for more info.

13.11.2025 | Michael Ebert

Warm your Drupal caches after a cache clear

We all know the problem that a Drupal site may be loading slowly after a cache clear.

tags:
  - { name: cache_prewarmable }
/**
  * Implements \Drupal\Core\PreWarm\PreWarmableInterface.
  */
public function preWarm(): void {
  $this->getDefinitions();
}

Issue:

We all know the problem that a Drupal site may be loading slowly after a cache clear.

Prerequisites:

  • Drush ≥ 13.5
  • Drupal ≥ 11.2

Solution:

There is a new prewarm API introduced in Drupal 11.2. This allows you to add a `cache_prewarmable` tag to your services and implement a preWarm method. If you are using Drush version 13.5 or newer, it will automatically call a `cache:warm` as last step when doing a `drush deploy`.

This will only warm cache cache items that are used to build most pages, plugins and registries, but not render caching or anywhere like that. 

Furter informations can be found here: