Drupal notice unserialize() error at offset generally happens when loading an improperly serialized array from the variables table.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to fix drupal errors.
Typically, error will look as shown below:
PHP Notice: unserialize() [<a href='function.unserialize'>function.unserialize</a>]: Error at offset 6 of 10 bytes in \includes\bootstrap.inc on line 428
Depending on how caching is set on your site, you may only see this error sometimes. This happens because once the variables are cached they may not load every time.
Some Causes of Serialization Issues:
Around line 550 of bootstrap.inc in drupal 6 change the code to as follows.
This will show you the variables that are throwing errrors. The @ symbol before unserialize suppresses the error so all the variables you can check before code execution stops:
// if ($cached = cache_get('variables', 'cache')) {
// $variables = $cached->data;
// }
// else {
$result = db_query('SELECT * FROM {variable}');
while ($variable = db_fetch_object($result)) {
$variables[$variable->name] = @unserialize($variable->value);
if ($variables[$variable->name] === FALSE) {
print "<hr/>Unserialize Error for variable:". $variable->name . '='. $variables[$variable->name] . "<br/>". $variable->value;
}
}
die;
cache_set('variables', $variables);
// }
After loading the variables, you may only get the error. After that they may be cache. So to reproduce the error, flush the cache via sql:
truncate table cache_block;
truncate table cache;
truncate table cache_content;
truncate table cache_filter;
truncate table cache_form;
truncate table cache_menu;
truncate table cache_views;
Once you find the bad variable(s), you will need to fix it in the database.
You may also override the variable by setting its value in the $conf array as described at the bottom of the settings.php file but you will not be able to change the variable value via the web interface until you remove the override in settings.php
Below are what serialized arrays should look like. (look in the variables table):
name: node_options_bio
value: a:1:{i:0;s:6:"status";}
name: googleanalytics_track_6
value: b:0;
The "i" represent integers, "s" strings, and the count is the length within the quotes.
You may be able to fix the value by hand editing the database table.
If you can't, you may just want to delete it, saving the old value somewhere, and let Drupal set it to its default. This may cause problems for some variables.
Ensure that the cose looks like this:
// Added by Deb
-- Open includes/bootstrap.inc file drupal 6.22
-- Go to line no 568
-- Paste below code after the line no 568 or "$variables[$variable->name] = unserialize($variable->value);" line.
if ($variables[$variable->name] === FALSE) {
variable_set($variable->name, ""); //here all the blank variable will be true
}
After changing all the necessary variables in the database (variable table), please delete the edited code and clear the cache and truncate the watchdog table, and refresh the page again.Check-in admin "recent log entries".
This article covers method to fix 'drupal notice unserialize() error at offset'. Basically, this error happens when loading an improperly serialized array from the variables table.