Sometimes you might have the requirement to override MySQL's default setting for wait_timeout
on Acquia Cloud Platform or Acquia Cloud 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..]
While implementing an override cannot be done on the MySQL server configuration, directly, as this level of configuration is centrally managed, you can override that setting on a 'per session' basis, i.e. for every PHP process that bootstraps Drupal.
In the code snippets below, the following names are used to represent specifics for your application:
MYSITE
is your docrootSITE
is your site URL or the mulitsite nameVARIABLE_NAME
is the MySQL variable nameThe following provides details for configuring the MySQL wait_timeout
value, depending upon your application installation configuration.
Do take these precautions:
settings.php
will look like. You should look for your existing 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 or 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.If you are not using BLT, you can add the following code snippet to settings.php
inside the Acquia require line section.
For Cloud Platform, not only do you need to set the wait_timeout
value, but you also need to set the value for interactive_timeout
.
Read through this article for more details.
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/MYAPP/MYAPP-settings.inc');
// For Cloud Platform you also need to raise the 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
);
}
}
You can verify that this setting is being applied by connecting to the database and looking up the appropriate MySQL variable, using the following drush
command.
Note, make sure that you replace SITE
with the site URL or the mulitsite name and VARIABLE_NAME
with the variable to check.
drush eval --uri=SITE 'print_r(Drupal\Core\Database\Database::getConnection("default", "default")->query("SHOW VARIABLES LIKE '\''VARIABLE_NAME'\'';")->fetchObject());'
In looking to verify the override values using a drush sql-cli
session, you might not see the set override values, which is why the Drupal\Core\Database\Database::getConnection function is being used.
This is an example of running the command to check the wait_timeout
value and expected output:
$ drush eval 'print_r(Drupal\Core\Database\Database::getConnection("default", "default")->query("SHOW VARIABLES LIKE '\''wait_timeout'\'';")->fetchObject());'
stdClass Object
(
[Variable_name] => wait_timeout
[Value] => 1200
)
This is an example of running the command to check the interactive_timeout
value and expected output:
$ drush eval 'print_r(Drupal\Core\Database\Database::getConnection("default", "default")->query("SHOW VARIABLES LIKE '\''interactive_timeout'\'';")->fetchObject());'
stdClass Object
(
[Variable_name] => interactive_timeout
[Value] => 1200
)
If this content did not answer your questions, try searching or contacting our support team for further assistance.
Thu Nov 21 2024 02:00:27 GMT+0000 (Coordinated Universal Time)