A machine-readable guide to this site for AI agents and language models is available at/llms.txt(https://dev.acquia.com/llms.txt on the production site).
If you must override the default MySQL wait_timeout setting on Cloud Platform or Site Factory, your logs can display an error similar to the following:
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in [..snip..]/core/lib/Drupal/Core/Database/[..snip..]On Cloud Platform, you cannot change the MySQL timeout on the MySQL server because it is a platform-wide setting. However, individual Drupal applications can override that setting on a per-session basis for every PHP process that bootstraps Drupal and connects to the database.
To override the setting, you must add configuration code to your settings.php file for Cloud Platform, or to your pre-settings-php and post-settings-php hooks for Site Factory.
settings.php file. Search for your existing require('/var/www/site-php/...') line and add the additional suggested lines around it.require('/var/www/site-php/...') multiple times in your code. You must call the statement one time and place any additional lines before or after that statement.1200 seconds or 20 minutes. Long Drush operations such as data imports or rebuilding Site Studio components can require larger timeout values.The following recommendations apply to Cloud Platform and Cloud Classic environments.
The recommended additions to settings.php start with a + sign:
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
+ );
+ }
}For Site Factory users, you must split the previous snippet into two parts:
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()After you add the appropriate snippet to your codebase, run a drush eval command to confirm that the overrides work for your application. Use the command as a starting point and modify it as required for your application. The command outputs the MySQL variables through the Drupal database connection defined in your settings.php file for Cloud Platform, or in your pre-settings-php and post-settings-php hooks for Site Factory.
# 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 command displays the values that you overrode.
The Drupal\Core\Database\Database::getConnection function is used because a drush sql-cli session might not display the override values.
The following is an example output:
interactive_timeout => 1200
wait_timeout => 1200