123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- $db = [
- 'class' => 'yii\db\Connection',
- 'dsn' => 'mysql:host=amic-mysql;dbname=amic_new',
- 'username' => 'work',
- 'password' => 'work',
- 'charset' => 'utf8',
- // Schema cache options (for production environment)
- //'enableSchemaCache' => true,
- //'schemaCacheDuration' => 60,
- //'schemaCache' => 'cache',
- ];
- $enableSlaves = true;
- $slavesrv = 'mysql:host=192.168.1.4;port=3307;dbname='.DB_NAME; //slave с распределение нагрузки
- /*
- Привышение нагрузки
- */
- if( file_exists('/.data2/status/cache_on.fl') ){
- $slavesrv = 'mysql:host=192.168.1.3;port=3306;dbname='.DB_NAME; //все на slave
- }
- /*
- Падение реплики
- */
- if( file_exists('/home/admin/www-bot/replica-stop_192.168.1.3.fl') ){ //реплика упала
- $enableSlaves = false;
- }
- if(defined("DB_DSN")){
- $port = "";
- if(defined("DB_PORT") && DB_PORT!=="") $port = ";port=".DB_PORT;
- $db = [
- 'class' => 'yii\db\Connection',
- 'dsn' => 'mysql:host='.DB_DSN.$port.';dbname='.DB_NAME,
- 'username' => DB_USER,
- 'password' => DB_PASSWORD,
- 'charset' => 'utf8mb4',
- // Schema cache options (for production environment)
- 'enableSchemaCache' => true,
- 'schemaCacheDuration' => 60,
- 'schemaCache' => 'cache',
- 'enableSlaves' => $enableSlaves,
- 'slaveConfig' => [
- 'username' => DB_USER,
- 'password' => DB_PASSWORD,
- 'attributes' => [
- // используем небольшой таймаут для соединения
- PDO::ATTR_TIMEOUT => 10,
- ],
- ],
- // список настроек для подчинённых серверов
- 'slaves' => [
- ['dsn' => $slavesrv ],
- ],
- ];
- }
- return $db;
|