PHP unserialize(): Error at offset
I have a problem with Drupal 6.20.
Possibly after a PHP update, site stopped working. I get:
Notice: unserialize() [function.unserialize]: Error at offset 0 of 22765 bytes in /PA开发者_运维百科TH/includes/cache.inc on line 33
This is the line:
$cache->data = unserialize($cache->data);
I would appreciate any help.
This problem will happen when you have Drupal 6.x running over PostgreSQL 9.0 because the bytea type was modified.
There are some suggested solutions here: http://postgresql.1045698.n5.nabble.com/Bytea-error-in-PostgreSQL-9-0-td3304087.html - (liking to Wayback Machine)
Running this on the database should fix it:
ALTER DATABASE databasename SET bytea_output='escape';
Sounds like your Drupal cache has gotten corrupted.
The immediate solution would be to clear the caches. Three ways to clear the Drupal caches:
Log in to the site with the admin password and select the flush caches option from the menu. This will obviously only be possible if you can get into the site in the first place.
If you can't do that, you can use the Drush command-line utility to flush the cashes without having to go to the site.
If you can't even get Drush to work (or you just don't want to install it), you can do it manually by going to the the database in your favourite MySQL tool, and emptying all the tables whose names start with the word "cache_".
The real question is why this would have happened in the first place. Sadly, I can't answer that, without a lot more info about your set up (and likely spending some time investigating too).
The danger is that even once you've cleared your cache, the same error could occur again, so even if you do get it working again, it would be a good idea to dig around a bit and see if you can find out the root cause.
My guess would be a rouge module that's got a bug has written bad data to the cache. You might want to check the drupal site and Google to check the modules you're using to see if there's any that have had similar behaviour reported.
Also, you mention a PHP update: Please let us know which versions of PHP you went from and to. There are known issues with some Drupal 6 modules in PHP 5.3, although the core does support it. See http://drupal.org/requirements for more info.
Try a var_dump($cache->data)
. It could be that PHP is adding escape sequences and/or quotes due to magic quotes or similar.
It is probably because of bad data inside of your array, you can fix it like this:
$data= preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $cache->data );
$s_data= unserialize($data);
精彩评论