简体   繁体   English

PHP unserialize():偏移时出错

[英]PHP unserialize(): Error at offset

I have a problem with Drupal 6.20. 我有Drupal 6.20的问题。

Possibly after a PHP update, site stopped working. 可能在PHP更新后,站点停止工作。 I get: 我明白了:

Notice: unserialize() [function.unserialize]: Error at offset 0 of 22765 bytes in /PATH/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. 当您在PostgreSQL 9.0上运行Drupal 6.x时会发生此问题,因为bytea类型已被修改。
There are some suggested solutions here: http://postgresql.1045698.n5.nabble.com/Bytea-error-in-PostgreSQL-9-0-td3304087.html - (liking to Wayback Machine) 这里有一些建议的解决方案: http//postgresql.1045698.n5.nabble.com/Bytea-error-in-PostgreSQL-9-0-td3304087.html - (喜欢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. 听起来你的Drupal缓存已经损坏了。

The immediate solution would be to clear the caches. 立即解决方案是清除缓存。 Three ways to clear the Drupal caches: 清除Drupal缓存的三种方法:

  1. Log in to the site with the admin password and select the flush caches option from the menu. 使用管理员密码登录站点,然后从菜单中选择flush caches选项。 This will obviously only be possible if you can get into the site in the first place. 如果您可以首先进入该网站,这显然是可能的。

  2. 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. 如果您不能这样做,您可以使用Drush命令行实用程序刷新现金而无需转到该站点。

  3. 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_". 如果您甚至无法让Drush工作(或者您只是不想安装它),您可以通过转到您喜欢的MySQL工具中的数据库手动完成,并清空所有名称以单词“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. 您可能需要检查drupal站点和Google以检查您正在使用的模块,以查看是否有任何已报告类似行为的模块。

Also, you mention a PHP update: Please let us know which versions of PHP you went from and to. 另外,您提到了PHP更新:请告诉我们您来自哪个版本的PHP。 There are known issues with some Drupal 6 modules in PHP 5.3, although the core does support it. PHP 5.3中的一些Drupal 6模块存在已知问题,尽管核心确实支持它。 See http://drupal.org/requirements for more info. 有关详细信息,请参阅http://drupal.org/requirements

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);

Try a var_dump($cache->data) . 尝试var_dump($cache->data) It could be that PHP is adding escape sequences and/or quotes due to magic quotes or similar. 由于魔术引号或类似原因,PHP可能会添加转义序列和/或引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM