Sometimes you might have the requirement to override MySQL's default setting for wait_timeout
on Acquia Cloud or Site Factory. One possible situation, is your logs may be showing messages like these:
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in [..snip..]/core/lib/Drupal/Core/Database/[..snip..]
On Acquia Cloud, changing the MySQL timeout can't be done on the MySQL server (as it is a platform-wide setting). However, individual Drupal applications can override that setting on a 'per session' basis, i.e. for every PHP process that bootstraps Drupal and connects to the database.
The way to do this is to add some code in your settings.php
file (for Acquia Cloud users), or in your pre and post settings hooks for Acquia Cloud Site Factory.
Do take these precautions:
require('/var/www/site-php/...')
line and then add the extra suggested lines around it.require('/var/www/site-php/...')
several times in your code; you must call it only once, ensuring you've placed any additional lines before/after that statement.1200
seconds (20 minutes); some long drush operations like data imports, rebuilding of Site Studio components, etc, may need larger timeout values.
The following recommendations are for both Acquia Cloud Platform infrastructure and Acquia Cloud Classic infrastructure environments which do not use Acquia BLT in their code base.
The recommended additions to settings.php
are in green.
if (file_exists('/var/www/site-php')) {
global $conf, $databases; $conf['acquia_hosting_settings_autoconnect'] = FALSE;
// Use your existing 'require' statement here
require('/var/www/site-php/XXXXXX/XXXXX-settings.inc');
// For Cloud Platform you also need to raise interactive_timeout
// See https://ahmedahamid.com/amazon-aurora-mysql-and-wait-timeout/
$databases['default']['default']['init_commands'] = array(
'wait_timeout' => 'SET SESSION wait_timeout=1200',
'interactive_timeout' => 'SET SESSION interactive_timeout=1200',
);
if (function_exists('acquia_hosting_db_choose_active')){
acquia_hosting_db_choose_active(
$conf['acquia_hosting_site_info']['db'],
'default',
$databases,
$conf
);
}
}
The following recommendations are for both Acquia Cloud Platform infrastructure and Acquia Cloud Classic infrastructure environments that use Acquia BLT in their code base.
If you are using BLT, look for your existing require...blt.settings.php
statement and add the recommended green lines around it.
if (file_exists('/var/www/site-php')) {
global $conf, $databases;
$conf['acquia_hosting_settings_autoconnect'] = FALSE;
// Use your existing 'require' statement here
require DRUPAL_ROOT . "/../vendor/acquia/blt/settings/blt.settings.php";
$databases['default']['default']['init_commands'] = array(
'wait_timeout' => 'SET SESSION wait_timeout=1200',
'interactive_timeout' => 'SET SESSION interactive_timeout=1200',
);
if (function_exists('acquia_hosting_db_choose_active')){
acquia_hosting_db_choose_active(
$conf['acquia_hosting_site_info']['db'],
'default',
$databases,
$conf
);
}
}
For Site Factory users the above snippet needs to be split in two. The first snippet should be placed in your pre-settings-php hook, and the latter on your post-settings-php hook:
pre-settings-php
global $conf, $databases;
$conf['acquia_hosting_settings_autoconnect'] = FALSE;
post-settings-php
$databases['default']['default']['init_commands'] = array(
'wait_timeout' => "SET SESSION wait_timeout=1200",
'interactive_timeout' => "SET SESSION interactive_timeout=1200",
);
acquia_hosting_db_choose_active();
drush eval
command below. You can use this command as a starting point and modify it as needed for your application's purposes.Note
You might not see the override values with a drush sql-cli
session, which is why the Drupal\Core\Database\Database::getConnection function is being used.
# Edit the Site URL
# Remove the last |egrep... section to see all variables.
drush --uri=[Site-URL] eval '$x = (array)Drupal\Core\Database\Database::getConnection("default", "default")->query("SHOW VARIABLES;")->fetchAll(); foreach ($x as $v) { echo $v->Variable_name . " => " . $v->Value . PHP_EOL; }' |egrep '^(wait|interactive)_timeout'
This should show the values you've overridden above.
An example output:
interactive_timeout => 1200wait_timeout => 1200
If this content did not answer your questions, try searching or contacting our support team for further assistance.
Wed Oct 22 2025 08:59:29 GMT+0000 (Coordinated Universal Time)