wesupport

25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

Need help?

Our experts have had an average response time of 11.43 minutes in March 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Drupal notice unserialize() error at offset

by | May 25, 2021

Wondering how to resolve ‘drupal notice unserialize() error at offset’? We can help you.

This error occurs when loading an improperly serialized array from the variables table.

Here at Bobcares, we often receive requests to resolve drupal errors as a part of our Server Management Services for web hosts and online service providers.

Today, let’s discuss the different causes for this error to occur and see how our Support Engineers fix it.

 

What are the causes of ‘drupal notice unserialize() error at offset’?

 

Typically, error will look as shown below

Error
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:

  • Firstly, changing serialized content via sql replace command such as when migrating a site. You can’t do this unless you follow up and put the length of the new value in by hand.
  • Then, serializing resources
  • Serializing objects and unserializing them without the class code loaded
  • Serialized string is truncated because it is too long for the field it is stored in.
  • Next, encoding/Decoding PHP/mysql issues
  • Incorrect installation/compilation/configuration of APC (php extension)

 

Debugging Technique

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;

 

How to resolve ‘drupal notice unserialize() error at offset’?

 

Today, let us see how our Support Techs resolved the error.

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.

How you can remove the above error?
// 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”

[Need any assistance in fixing drupal error? – We’ll are always there to help you]

Conclusion

In short, the error occurs when loading an improperly serialized array from the variables table. Today, we saw how our Support Techs fix it.

 

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Categories

Tags