By betolley on
I keep getting the error:
Notice: unserialize(): Error at offset 2 of 52 bytes in C:\Inetpub\UC Pub\includes\bootstrap.inc on line 130
warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\UC Pub\includes\bootstrap.inc:130) in C:\Inetpub\UC Pub\includes\common.inc on line 99.
I get it randomly on any page.
Comments
How to fix it...
For me, this happened after having tried the Rep[lacement] Tags module. Somehow the module's database entries became corrupt. Several of them reported strings at a certain length and then the strings were a completely different length altogether. That caused the
unserialize()function to fail and PHP issued 6 notices that kept popping up at the bottom of my screen over and over (as I learned elsewhere, you can reliably get the PHP notice if you submit the Admin>Settings page.)A friend of mine helped me out with some debugging to try and track down the database entries that were causing the issue. To do so, we first tracked down the line in boostrap.inc that was reported in the PHP notice (in your case it seems to be line 130). In my case (and I would assume in your case), the line contained a call of
unserialize(), and particularly in my case it was contained within thevariable_initfunction. I commented out that line and replaced it with the snippet my PHP-whiz friend whipped up.The original bootstrap.inc
variable_initfunction:And the
variable_initfunction after:This allowed me to see what database variable was incorrect by dumping a list of variables that did not meet certain conditions when creating the page. These conditions may or may not be the same for you, I guess, so there may be some more work involved here. Anyway, I discovered the exact reason why I had 6 or so PHP Notices popping up at the bottom of random pages: there were 6 database entries that were bad. I loaded up phpMyAdmin and surgically removed them. (Be careful, of course.) In my case they were leftover reptag entries. (I had previously removed the module, having once suspected it as the culprit. I neglected, of course, to remove its database entries.) Anyway, once I got rid of the offenders, I restored bootstrap.inc to its original state, and all was well!
Of course, I was lucky.. my offenders were useless database entries I could simply remove; I figure it could have been worse.
It's not much, but it's a start.
Unserialize problem solved
Thanks for this.
I recommend everybody whith bootstrapserrors to debug this way. My cron.php was hanging for minutes.
I discoverd about 35 variables in {variable} failing. After removing these, cron is running again smoothly with no errors.
Thanks
update to changed function in drupal 5.8 (and 5.7, 5.6 I assume)
Thanks for the solution.
I just wanted to update it, because function parameters have changed.
This is my proposal:
My changes are: added 'cache' variable to cache_get and cache_set list of parameters, and instead of outputing the error to page for a user to see, I changed "echo" into "error_log" where first parameter is the message, and the second is type of message (=0) so that the error would go to apache php error log.
Again, thank you LaurenH, and your PHP guru friend :)
Thanks to LaurenH for your
Thanks to LaurenH for your excellent contribution!
I encountered the same problem when unloading and then restoring my database to a different location. Without this temporary modification to bootstrap.inc, I don't know if or when I would have been able to correct the problem.
By the way, The Drupal version I am using is ver 5.14. The change alteration as posted by LaurenH worked just fine without any modification. I didn't take the opportunity to attempt the code contributed by camypaj, so I cannot comment regarding it's effectiveness.
Thank you, that worked
In my case, this was caused by moving from MySQL on a Windows box, to MySQL on a Mac, but your debugging solution worked. Thanks.
xtfer.com
platform.sh
Would also like to comment
Would also like to comment that this solution helped me. AGAIN. (I think this is the second time I've used it and had excellent luck with it.)
I think this time it was a drush updatedb problem that caused some updates to fail prematurely.
In any event, thanks! This should become some part of the official documentation.
Have I helped you? Consider buying me a beer.
Another way to debug
I get these periodically too, and just figured out what for me is a better way to debug them. The other posters on this thread advice making changes to bootstrap.inc, but any changes to echo out the variable names causes those to be echoed out on every page load - something that isn't tolerable on a production server.
My solution is as follows:
use your mysql command line client (or, I suppose, something like phpmyadmin) to issue the folllowing bit of SQL against your drupal database:
select name,length(value), value from variable where length(value) = <the last byte value on the error message>;
so, for the poster above:
select name, length(value), value from variable where length(value) = "52";
This will show you the variable name and value that is being handed to the unserialize() function, and you can start more in-depth debugging from there. Of course, if you have more than one variable with a value of length "52" then you'll have more than one thing to look at.
Great tip... easy to do and works... more how-to
This query did indeed isolate the "usual suspects" and allowed me to identify the errant data.
Further how-to advice: Once you have these suspects in your sights, another part of the error message can help you isolate the problem. That is, the byte count points to the char in the serialized string where PHP burped. In my case, the serialized data string length was wrong, a digit dropped by a gremlin apparently. I counted the length of the serialized string and popped in the correct length in the serialize prefix/spec, saved the record, and voila! Away went the error. Thanks, Malcolmpdx for this practical and useful tip.
This [#13] is brilliantly
This [#13] is brilliantly helpful - thanks malcolmpdx
this is pretty rediculous,
this is pretty rediculous, but just in case someone has been as rediculous as me ...
I developed my site on localhost.
Therefore my temp dir variable (file_directory_temp) was set to
When I went ahead and put the site live I copied over the database and went into the variables database hardcore to change the variable to
...I forgot to change the s value "36" to match the length of the new temp-dir string ...
So it had to be
I'm sure there are other ways to set this variable to the right value automatically (by running update.php maybe?) , but haven't found them yet
I used the above mentioned SQL query method to look up (directly in the database) what variables were causing the problems first.
My issue was related to
My issue was related to UTF-8. String shorter - character-wise (because contained UTF-8) but unserialized expecting longer one.
Solution:
function mb_unserialize($serial_str) {
$out = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $serial_str );
return unserialize($out);
}
and
$variables[$variable->name] = mb_unserialize($variable->value);
instead of
$variables[$variable->name] = unserialize($variable->value);
None of the above code found in bootstrap.inc
I am getting the below error using 7.0-alpha6
* Notice: unserialize(): Error at offset 32 of 33 bytes in variable_initialize() (line 762 of /public_html/includes/bootstrap.inc).
* Notice: unserialize(): Error at offset 21 of 22 bytes in variable_initialize() (line 762 of /public_html/includes/bootstrap.inc).
* Notice: unserialize(): Error at offset 926 of 5585 bytes in variable_initialize() (line 762 of /public_html/includes/bootstrap.inc).
* Notice: unserialize(): Error at offset 1008 of 1010 bytes in variable_initialize() (line 762 of /public_html/includes/bootstrap.inc).
I created a site on one domain that is working ok, I copied all files & db to anover domain and updates all reference to the old domain in the db and updated the sites/default/settings.php
I tried to run update.php but returned all was good along with the above.
Not sure if this was the right way to copy the site and have not tried the otehr methods as I was looking for a permanent fix, as I will need to copy the site again.
Probably need to look at multi site options later but am new to this
Thanks in advance
Turns ON or OFF some PHP extensions will resolve this issue.
Hello,
I have also reached this issue. I have tried to change some PHP extensions and then the issue has been resolved. The extensions below:
- magic_quotes_runtime -> Turns it OFF
- register_argc_argv -> Turns it ON
Hope this will help you...
- register_argc_argv -> Turns
- register_argc_argv -> Turns it ON
This did fix the problem for me even though I don't understand how or why.
Worked!
I was having the same issues on Drupal 6.19 with PHP 5.2.6 and this worked for me. Thanks so much!
Thanks, this fixed my issue.
Thanks, this fixed my issue.
This is still a helpful
This is still a helpful troubleshooting tip 5 years later - thanks! One thing I noticed is that this code will echo the variable if it is set to NULL. It doesn't mean that the variable is hitting the unserialize() error.
Maybe add in an extra condition to the check:
$variable->value != serialize(NULL) &&
variablecheck module
But the code has changed for D7
My error:
Notice: unserialize() [function.unserialize]: Error at offset 2 of 8 bytes in variable_initialize() (line 748 of /home1/explore8/public_html/2tim/includes/bootstrap.inc).
Doesn't help because the SQL:
select name, length(value), value from variable where length(value) = "8";
finds 100s of variables
I'd rather not just cover up the error as suggested, or it might bite me later.
Found it. There is now a module to find bad variables http://drupal.org/project/variablecheck
Install it, go to your status report, run the variable check, tell some module developers about bad variable where appropriate,
then using phpmyadmin, click on variable table, search tab, look for your variable using %like%, delete where you can afford it
.
.
--
Bram Moreinis
Greenfield Digital
http://greenfielddigital.com
There is now a module to find
This solved the mentioned error on my install!
You saved my day! Thanks very much.
Success!
This worked for me. I was getting this error while installing modules on a new site, I hadn't even enabled them yet.
My problem was that I had installed Drupal using a "simplescripts" wizard provided my by host's cPanel (it's the only way I can get 1-click updates for Drupal core), and it put a bad string into the "site_email" variable (it tried to pull my email address from my cPanel profile, thinking it was being helpful... bad wizard!).
In my case, it was a simple matter of updating the field in site configuration, I didn't need to edit the database.
Thanks for posting this solution!
BTW, maybe this is an update since this suggestion was posted, but the Variable Check module allows you to delete offending entries directly from its status page, instead of making you go to phpMyAdmin. Although that seems to take a casual attitude toward it that might give inexperienced Drupal admins some trouble if they just assume deleting bad entries will automatically fix their problem.