PHP Notice: unserialize() … : Error at offset 6 of 10 bytes in … on line 428

Posted by


PHP Notice:  unserialize() [<a href='function.unserialize'>function.unserialize</a>]: Error at offset 6 of 10 bytes in on line 428

Debugging Technique

Around 480 of in drupal 6 change the code to as follows. (Set aside the old code to replace afterward) This will show you the variables that are throwing errrors. The @ symbol before unserialize suppresses the error so all the variables can be checked 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 “Unserialize Error for variable:”. $variable->name . ‘=’. $variables[$variable->name] . ”
“. $variable->value;
cache_set(‘variables’, $variables);
// }

You may only get the error when variables are first loaded. After that they may be cached. 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;