When I was analysing performance of a one Drupal powered website, I need to count number of Drupal variables and their approximate size in memory. I used my beloved module Devel. Devel itself contains tool called "Variable editor" (it is a big form, where you can adjust Drupal variables directly). Unfortunaltely man can't simply get the count or size of variables and because there is no pagination and number of variables was quite big I was getting PHP memory limit error each time when I tried to access this page.
Simple and quick solution is opening the "Execute PHP Code" page in the Development block (Drupal vets are writing
/devel/php to the address bar directly ;-) ...) and enter following code to the textarea:
<?php // Print approx. total number of variables // Note: you can also use drupal_set_message() dvm(count($GLOBALS['conf'])); // Prints approx. size of variables in B/KB // Note: you can also use drupal_set_message() dvm(format_size(mb_strlen(serialize($GLOBALS['conf']), '8bit'))); // Prints whole $conf array to the collapsed tree using Krumo library dpm($GLOBALS['conf']); // Alternatively you can use plain-text output dvm($GLOBALS['conf']); // or dpr($GLOBALS['conf']); ?>
I measure these values: count of variables was unbelievable 8297, size of the serialized variables field was 695.46 KB. What's yours results?
NOTE: Originaly posted to my Drupal.cz blog (in Czech language): http://www.drupal.cz/blog/wojtha/kolik-ma-instalace-drupalu-promennych