Drupal Dump

Drupal Snippets, Hacks and more....

473 posts since 2011

503 Max restarts limit reached

So we had "503 Max restarts limit reached" problem on our production while doing some batch operations and some edits of entities. Problem for both was that server response was slow as both have large queries running which take more than 20 seconds(yeah should be optimized and probably add some indexes to fields).

Getting country name from country code

To get full country name you need to use CountryManager class and you can then get all the info you need.  So lets say you have some country code store in $shipping_code variable, to get full country name

Xdebug profiler on Mac OSx

Calling this 3 commands should help you install qcachegrind so you can read xdebug profiler files you made

# Install qt
brew install qt

# Install qcachegrind
$ brew install qcachegrind
# Install graphviz
$ brew install graphviz

run qcachegrind in CLI and it will open up app in window where you can import profile file.

Run composer without "Discard changes" question

You want to keep composer quite and just do its job? Then either set that to your composer.json config with

composer config --global discard-changes true

Which will add that config to your config.json and everbody will have this setting or you can just make this one liner to keep it shut.

Checking all crontabs on server

To get all crontabs from users on your system write this one liner

for user in $(getent passwd | cut -f1 -d: ); do echo $user; crontab -u $user -l; done

to check other crons you need to see what is in for example 

ls -la /etc/cron.daily


How to login to drupal over postman or CLI (Authorization: Basic)

To login to drupal and POST/PATCH some endpoint over JSON:API you need to login first, this is simple over postman, just go to Authorization TAB, select Basic Auth and fill in your user/pass and this will be automatically added to your header. You could also make it manually adding header with calculated base64 username:password, which you can get with CLI and

JSON:API disable caching locally

To disable caching while testing your JSON:API endpoints you should put this into your settings.php

$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';

but for this to work, you need to define this service null, which should be added as

Get list of all installed modules and their dependencies

You probably don't need this but for debugging purposes i checked system.install file and saw how dependencies are checked on drupal updates.
So to get full list of modules and its info run

$files = \Drupal::service('extension.list.module')->getList();

to get theme info go