1

I have project on php (Yii2) and DB (PDO).

I have an exident. DB in project is not critical, project works with external API.

I have connection timeout - 5 sec.

return [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=xx.xx.xx.xx;dbname=db_name',
    'username' => 'user,
    'password' => '',
    'charset' => 'utf8',
    'attributes' => [
        PDO::ATTR_TIMEOUT => 5
    ]
];

But it is timeout on connection to DB.

But if I already connected to DB, server down in swap and I need wait until receive answer as long as DB will get up, even if timeout only 5 sec.

How I can set common timeout? That if I will not receive answer in 5 sec, drop connection.

user2264941
  • 407
  • 1
  • 8
  • 23
  • Have you tried setting the socket timeout on php level? http://stackoverflow.com/questions/29493197/phps-pdo-is-ignoring-the-attr-timeout-option-for-mysql-when-server-cannot-be-re – Shadow Mar 20 '17 at 15:31
  • I saw it, but I don't think, that it is the besst way. And what about other services where I need use sockets, more then 5 sec? – user2264941 Mar 20 '17 at 16:35

0 Answers0