This mini module will set the max_allowed_packet session variable for MySQL at the start of each page view.
It is meant as a solution for environments where you don't have access to the global max_allowed_packet variable and the provider can't or won't increase it for you.

Note that this no longer works with MySQL 5.0.x or newer. Setting this variable per session is allowed in 4.1.x but is ignored in 5.1.x and ignored in 5.0.x. Further, this variable is read-only as of MySQL 5.0.84 and 5.1.31. You can check which version of MySQL you are running on your site's status report, at admin/reports/status.

The info file (save as max_packet.info):

name = Max packet
description = Utility module that tries to increase the size of the max_allowed_packet session variable for MySQL.
core = 6.x

Make sure the description is on one line otherwise Drupal will mark the module as incompatible

The module file (save as max_packet.module):

/**
 * Implementation of hook_init().
 */
function max_packet_init(){
  //Set the value to 16 MB.
  db_query('SET SESSION max_allowed_packet=16*1024*1024');
}

/**
 * Implementation of hook_help().
 */
function max_packet_help($path, $arg) {
  $output = '';
  switch ($path) {
    case "admin/help#max_packet":
      //Retrieve the current value to see if the module is working
      $result =  db_query("SHOW VARIABLES LIKE 'max_allowed_packet'");
      while ($variables = db_fetch_object($result)) {
        $current_max_packet = $variables->Value / (1024 * 1024);
      }      
      $output = '<p>'.  t("Current value of max_allowed_packet: !current_max_packet MB", array('!current_max_packet' => $current_max_packet)) .'</p>';
      break;
  }
  return $output;
}

When you look at the help page of this module you can tell if the session variable was set successfully.