April 19

0 comments

Annoying Drupal Error – Notice: unserialize() [function.unserialize]: Error at offset 1066 of 1068 bytes in variable_initialize()

By NickLitten

April 19, 2012

drupal

So, for the last several months I’ve been getting this very annoying drupal error message on virtually every page on the website:

Notice: unserialize() [function.unserialize]: Error at offset 1066 of 1068 bytes in variable_initialize() (line 943 of /home/projex/www/www/includes/bootstrap.inc).

I had researched it… tried hacking some little PHP snippets… tried cleaning up the SQL database… all to no avail. But today is a cause for celebration and dancing in the streets. Because its gone! Huzzah! All thanks to a couple of smart drupal chappies and chappettes on various websites who have probably forgotten more about the Drupal Database than I will ever know.

This error is caused by a corruption in the database it self… mainly in a variable called ‘variable’ which contains an invalid value. So, all we have to do is to find that duff variable and kill it. I chose the method of hitting it with a stick until it ran screaming from the room and straight off a cliff outside the door… falling two miles and landing in quicksand… inhabited by a special breed of quicksand loving Piranha. They made short work of this cheeky little error… I can tell you.

Drupal 7 has a new and efficient way of loading module and theme settings from the database. The new loader requires all settings to be stored in the current (serialized) format. An unfortunate side effect is that any left-over settings from modules that did not clean up when they were uninstalled, and are not stored in the correct format, cause PHP notices on your site.

This may happen if you’ve for instance upgraded a site from Drupal 5, through Drupal 6 to Drupal 7.

So to find the value in error just search using the second byte value. ie:

SELECT name, LENGTH( value ) , value
 FROM variable
 WHERE LENGTH( value ) = "1068"

This turned up a message telling me that a value of ‘theme_amlekula_settings’ was the culprit. this is an old Theme I was playing with back in Drupal 5 and Drupal 6 days… so its been sitting in there all this time and waiting to bite me. So, I deleted that value from the table doing this:

DELETE FROM `your-sql-filesname`.`variable` WHERE `variable`.`name` = 'theme_amlekula_settings';

and TADA!!! its gone.

I also took the opportunity to sift through all the values defined in VARIABLE and found lots of old values left behind from various installations during my Drupal adventures from Version 5 through 6 and now into 7.

Housekeeping is a good thing and it scares the error messages away.

Until the next time 🙂

NOTE: I just read another comment which recommends using a drupal module ‘variablecheck’ which checks the database searching for old and duff values. This module lists all entries in the {variable} table that cause unwanted PHP notices on production sites, such as:

Notice: unserialize() [function.unserialize]: Error at offset 74 of 75 bytes in variable_initialize() (line 749 of /srv/www//includes/bootstrap.inc).

By knowing the offending variable name, you can remove it from the database, making the notice go away. Of course, you should probably notify the module or theme author that their module or theme does not properly clean up after itself.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips

>