0

I am working to solve this error but unable to find the reason as I am new for drupal Error at offset 2 of 16 bytes in bootstrap.inc on line 936 when I open /var/www/html/mysite/includes/bootstrap.inc I have found this

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

error is showing on this line $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed()); I am unable to to solve it, what is the reason ?

Kanika
  • 61
  • 5
  • Hi @Kanika, there were typos in my answer but I fixed them! Please leave a comment to tell me if it was helpful or if you find anything wrong. Thank you – EricLavault Oct 25 '16 at 18:04
  • @ericLavault i am still working on it, once your solution work let you know – Kanika Oct 26 '16 at 05:48

1 Answers1

0

This error means that unserialize() fails to convert a serialized value back into a PHP value because of an invalid length (or a length mismatch) in the stored representation of the data.

The reason is that some variable was badly serialized, see this detailed answer for more info.

To resolve the issue, first check variable table and ensure the value data type is a blob type. For database portability blob fields must be used to store serialized data since PHP adds null bytes if objects are serialized. Null bytes cannot be stored in Postgres text or varchar fields. The exact type depends on the underlying database :

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

Then you need to identify the variable(s) causing the issue, run this code and check the output :

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

Once the "broken" variable is identified, you might want to delete it or reset it using variable_del() or variable_set().

To prevent the issue, one should avoid setting variables manually and always use variable_set().

Community
  • 1
  • 1
EricLavault
  • 12,130
  • 3
  • 23
  • 45