Twice in the last few months, one of my Drupal sites has become unavailable due to a corrupted sessions table. A quick MySQL "REPAIR TABLE sessions;" solved the problem, but I'd like to have it done automatically and prevent the need for human intervention.

I'm currently testing a fix where I modify cron.php to run the following code once per hour:

$query = "REPAIR TABLE sessions;";
$result = db_query($query);
while ($row = db_fetch_object($result)) {
  $rows[] = object2array($row);
  $status = $row->Msg_text;
  if ($status != 'OK')
  {
    watchdog('cron', 'Drupal session table repair: ' . $status, WATCHDOG_ERROR);
  }
}

It seems to be working fine, but I'm wondering if there are any problems with this change that I may not be aware of. Or, for that matter, if this will actually help anything. I'm also curious why something like this isn't part of the standard Drupal installation, given how session table corruption appears to be a regular issue.

Any insight into this matter would be appreciated.

--R.J.
http://www.electric-escape.net/