Module Monday: Variable Check

How to Find Broken Values When You Get an Unserialize Error Message (Drupal 6 and 7)

Ever run into errors like the following on your Drupal sites? Notice: unserialize() [function.unserialize]: Error at offset 74 of 75 bytes in variable_initialize() (line 749 of /srv/www/<sitename>/includes/ This is a symptom of an invalid variable in the {variables} table. When the Drupal cache is cleared (or variable_set() is called), Drupal queries the variable table for all site settings and saves them in your cache for quick access. If you're getting errors like the above, odds are your variable table contains a corrupted or unserialized value. So now that you know what the problem is, how do you solve it? For larger sites there can be hundreds, if not thousands of variables in the {variables} table. Finding the broken value can be time consuming and difficult. Enter Variable Check! Once the Variable Check module is installed, a new report is added to the Reports section in the site administration.

Invalid Variables administration screen

As we can see, Variable Check is correctly identifying an invalid string length, an unserialized value, and a missing quote from a string value. Variable Check also adds an entry to the site status report, alerting site administrators if any invalid variables are ever added to the site. Note that Variable Check will only find variables that fail to unserialize; it can't detect variables that are syntactically correct but logically incorrect (such as a string that a module expects to be an array, or a TRUE that should be FALSE for your site). Once a broken variable has been identified, the variable can be deleted in the user interface or with drush vdel. Or, drush can be used to correctly reset variables. $ drush vset site_name "Kitten Emporium" There's also a core issue open to address invalid variables directly in Drupal itself. Be sure to check out Use variable_initialize() against broken values - Notice: unserialize() [function.unserialize]: for the current status.

Get in touch with us

Tell us about your project or drop us a line. We'd love to hear from you!