'How to solve yii2 execution time out error with multiple databases
I have setup two database connections in my application. One for mysql and the other for oracle db. I have tested both connections individually by reading data from tables in each database and everything works fine. When generating a model using gii with the db2 as the database connection id, I get a timeout error. I have increased the execution time of the script to 300 seconds and still get the execution timeout error. When using db with gii it works ok.
The db config in the db.php is as shown:
return [
'mysql' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=' . DATABASE_SERVER . ';port=' . DATABASE_PORT. ';dbname=' . DATABASE_NAME,
'username' => DB_USER,
'password' => DB_PASS,
'charset' => 'utf8',
],
'oracle' => [
'class' => 'yii\db\Connection',
'dsn' => 'oci:dbname=//dbserver:dbport/dbname;charset=UTF8',
'username' => 'username',
'password' => 'password'
],
]
In my web.php I have this:
$db = require __DIR__ . '/db.php';
$config = [
//
'components' => [
//
'db' => $db['mysql'],
'db2' => $db['oracle'],
//
]
//
]
Solution 1:[1]
try to increase connection timeout. in main-local.php
'db' => [
'attributes' => [
PDO::ATTR_TIMEOUT => 10, // timeout value in seconds
]
]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ehab AL-amawi |
