Reply to comment
Drupal 8 on-demand error display with disabled cache via URL Parameter
Have you ever wanted to disable Drupal 8 cache and enable error reporting only for a specific page or to quickly debug a problem?
Here's a simple solution how to enable debugging and disable caching for a single call using a URL debug parameter
Some months ago I created a Drupal Core feature request issue for this topic, where you can read details: https://www.drupal.org/project/drupal/issues/2947316
Now I'd like to share my results and working solution with you.
Solution summary:
The solution was to use a snippet to attach some debug/development code in settings.php and this way also load a debug/development services.yml file if the secret URL parameter "&QUICKDEBUG=1" is present.
So if you call for example https://www.example.com/node/123?&QUICKDEBUG=1
this will disable all caches and enable error_reporting and display_errors.
This should of course NOT be used in production but is a helpful little trick for easy debugging without switching the whole environment status.
Solution code
At the end of your general settings.php you append the following code:
- // ----------------------------- Error reporting: -----------------------------
- ///* -- Escape this line to enable error reporting inpage.
- $conf['error_level'] = 2; // Show all messages on your screen
- // Load the disabled DEVELOPMENT SETTINGS for this QUICKDEBUG call:
- include_once $app_root . '/' . $site_path . '/__settings.QUICKDEBUG.php';
- }
- }
- // */
Which will set some php variables to display errors and appends __settings.QUICKDEBUG.php to override some settings.php variables.
__settings.QUICKDEBUG.php contains the variables you want to override for QUICKDEBUG. Furthermore it has to add our __services.QUICKDEBUG.yml file with this code:
- $settings['container_yamls'][] = $app_root . '/' . $site_path . '/__services.QUICKDEBUG.yml';
- }
We need to do this because the services.yml also sets some variables like twig cache, debugging and cache backend. For example the file may look like this:
parameters:
http.response.debug_cacheability_headers: true
twig.config:
debug: true
auto_reload: true
cache: false
services:
cache.backend.null:
class: Drupal\Core\Cache\NullBackendFactory
That's it. Place your custom
- __settings.QUICKDEBUG.php
- __services.QUICKDEBUG.yml
in your sites/default directory and have a happy debugging time :)
Reply
Julian Pustkuchen, M. Sc. Wirtschaftsinformatik ist passionierter Software- & Webentwickler mit den Schwerpunkten Softwaredesign, Objektorientierung sowie Usability- & Ablaufoptimierung bei webks. Ein weiterer Schwerpunkt ist die Entwicklung im CMS Drupal.
Entwickelt Julian gerade keine Software, fährt er Ski, Mountainbike, spielt Badminton, segelt oder verbringt Zeit mit Freunden.
Dieser Blog dient als sein "öffentlicher Notizblo(ck/g)".
Webbasierte Lösungen? Machen wir!
webks: websolutions kept simple
http://www.webks.de
Dir hat dieser Beitrag viel Zeit und Nerven gespart?
Dann freue ich mich über jede kleine Anerkennung:
Oder du suchst weitere professionelle Unterstützung?
Dann bietet dir unser webks.de Softwareentwickler-Team professionelle Dienstleistungen im Web-Development und der Drupal CMS Entwicklung!