Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JPustkuchen/a5f1eaeb7058856b7ef087b028ffdfeb to your computer and use it in GitHub Desktop.
Save JPustkuchen/a5f1eaeb7058856b7ef087b028ffdfeb to your computer and use it in GitHub Desktop.
Drupal 8 kint set maxLevels in settings.php to prevent out of memory

Currently devel doesn't allow to override KINT configuration in a clean way. Hopefully this will be possible some day via setting in UI or drupal setting override in settings.php Until this happens you may use this dirty trick in settings.php to override the setting.

See issues:

Simply copy this into your settings.php and change the value accordingly (Kint default: 7)

Kint ^3:

// Change kint maxLevels setting:
include_once(DRUPAL_ROOT . '/modules/contrib/devel/kint/kint/Kint.class.php');
if(class_exists('Kint')){
  // Set the maxlevels to prevent out-of-memory. Currently there doesn't seem to be a cleaner way to set this:
  Kint::$maxLevels = 4;
}

Kint >=4:

// Change kint maxLevels setting:
if (class_exists('Kint')) {
  \Kint::$depth_limit = 5;
}
@nop1984
Copy link

nop1984 commented Dec 6, 2021

comment just to say this snippet is valuable, coming here at least once in 2 months to remind the details
thanks :)

@radube
Copy link

radube commented Jan 15, 2022

Just wanted to comment that at least for kint 4.1.1 you need to use \Kint::$depth_limit instead of \Kint::$max_depth. I hope that helps somebody to save some time 🙂

@JPustkuchen
Copy link
Author

Thank you @radube, updated the snippet accordingly :)

@kendallsvcr
Copy link

Just in case someone isn't quite sure about how to use it when is having the memory error (running out of memory) now a days with Drupal 8/9 just go to your settings.php or maybe a settings.local.php (for those who use it) and place this:

// Change kint depth_limit setting.
if (class_exists('Kint')) {
  // Set the depth_limit to prevent out-of-memory.
  \Kint::$depth_limit = 4;
}

note that as @radube said, for kint 4 it suffered a change from $depth_limit to $max_depth (thanks mate!)

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Si tienes el problema de usar kint pero el sitio se queda sin memoria, utiliza el codigo anterior, directamente en el archivo settings.php o tal vez settings.local.php

@djassie
Copy link

djassie commented Apr 13, 2023

wokring -

if (class_exists('Kint')) {
  // Set the max_depth to prevent out-of-memory.
  \Kint::$max_depth = 4;
}

@djdemonNet
Copy link

Kint ^5 has the same syntax as and Kint ^4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment