第936行的bootstrap.inc中偏移量为2的16字节错误

时间:2016-10-24 11:01:49

标签: drupal drupal-7

我正在努力解决此错误但无法找到原因因为我是drupal Error at offset 2 of 16 bytes in bootstrap.inc on line 936的新手 当我打开/var/www/html/mysite/includes/bootstrap.inc时我发现了这个

function function variable_initialize($conf = array()) {
  // NOTE: caching the variables improves performance by 20% when serving
  // cached pages.
  if ($cached = cache_get('variables', 'cache_bootstrap')) {
    $variables = $cached->data;
  }
  else {
    // Cache miss. Avoid a stampede.
    $name = 'variable_init';
    if (!lock_acquire($name, 1)) {
      // Another request is building the variable cache.
      // Wait, then re-run this function.
      lock_wait($name);
      return variable_initialize($conf);
    }
    else {
      // Proceed with variable rebuild.
      $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed());
      cache_set('variables', $variables, 'cache_bootstrap');
      lock_release($name);
    }
  }

  foreach ($conf as $name => $value) {
    $variables[$name] = $value;
  }

  return $variables;
}

错误显示在此行$variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed()); 我无法解决,是什么原因?

1 个答案:

答案 0 :(得分:0)

此错误表示由于存储的数据表示中的长度(或长度不匹配)无效,unserialize()无法将序列化值转换回PHP值。

原因是某些变量被严重序列化,请参阅详细answer以获取更多信息。

要解决此问题,请先检查variable表并确保value数据类型为 blob 类型。对于数据库可移植性,必须使用blob字段来存储序列化数据,因为如果对象被序列化,PHP会添加空字节。空字节不能存储在Postgres文本或varchar字段中。确切的类型取决于底层数据库:

  • MySQL:LONGBLOB
  • PostgreSQL:BYTEA
  • SQLite:BLOB

然后您需要识别导致问题的变量,运行此代码并检查输出:

$var = array();
$broken_var = array();
$false = serialize(FALSE);

$rows = db_query('SELECT name, CONVERT (value USING utf8) FROM variable')->fetchAllKeyed();
foreach ($rows as $name => $value) {
  $var[$name] = @unserialize($value);
  if ($var[$name] === FALSE && $value !== $false) {
    $broken_var[$name] = $value;
  }
}

print_r($broken_var);

一旦"破坏"标识了变量,您可能希望将其删除或使用variable_del()variable_set()重置该变量。

为防止出现此问题,应避免手动设置变量并始终使用variable_set()