Bobcares

WeSupport

Call Us! 1-800-383-5193
Call Us! 1-800-383-5193
Call Us! 1-800-383-5193

Need Help?

Emergency Response Time custom

Our experts have had an average response time of 11.06 minutes in March 2021 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 *

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF