[icinga-checkins] icinga.org: icingaweb2/feature/ pdo-attr_timeout-hardcoded-in-dbconnection-10178: DbResourceForm: make DB connection timeout configurable

git at icinga.org git at icinga.org
Wed Oct 19 18:06:52 CEST 2016


Module: icingaweb2
Branch: feature/pdo-attr_timeout-hardcoded-in-dbconnection-10178
Commit: df8ec8fa7d0a45b78312031d94b58d81818d0790
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=df8ec8fa7d0a45b78312031d94b58d81818d0790

Author: Alexander A. Klimov <alexander.klimov at icinga.com>
Date:   Wed Oct 19 18:05:38 2016 +0200

DbResourceForm: make DB connection timeout configurable

refs #10178

---

 application/forms/Config/Resource/DbResourceForm.php |   13 +++++++++++++
 library/Icinga/Data/Db/DbConnection.php              |    3 ++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/application/forms/Config/Resource/DbResourceForm.php b/application/forms/Config/Resource/DbResourceForm.php
index cf85e13..e72676c 100644
--- a/application/forms/Config/Resource/DbResourceForm.php
+++ b/application/forms/Config/Resource/DbResourceForm.php
@@ -157,6 +157,19 @@ class DbResourceForm extends Form
                 'label'         => $this->translate('Persistent')
             )
         );
+        $this->addElement(
+            'number',
+            'timeout',
+            array(
+                'label'             => $this->translate('Timeout'),
+                'description'       => $this->translate(
+                    'How many seconds to wait for reply from the database server.'
+                    . ' Zero means infinite. Leave empty to use the default'
+                ),
+                'min'               => -1.0,
+                'step'              => 1.0
+            )
+        );
 
         return $this;
     }
diff --git a/library/Icinga/Data/Db/DbConnection.php b/library/Icinga/Data/Db/DbConnection.php
index 81afb2c..750c239 100644
--- a/library/Icinga/Data/Db/DbConnection.php
+++ b/library/Icinga/Data/Db/DbConnection.php
@@ -60,7 +60,6 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
     );
 
     private static $driverOptions = array(
-        PDO::ATTR_TIMEOUT    => 10,
         PDO::ATTR_CASE       => PDO::CASE_LOWER,
         PDO::ATTR_ERRMODE    => PDO::ERRMODE_EXCEPTION
     );
@@ -125,6 +124,8 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
     {
         $genericAdapterOptions  = self::$genericAdapterOptions;
         $driverOptions          = self::$driverOptions;
+        $timeout = $this->config->timeout;
+        $driverOptions[PDO::ATTR_TIMEOUT] = $timeout === null || $timeout === '' ? 10 : (int) $timeout;
         $adapterParamaters      = array(
             'host'              => $this->config->host,
             'username'          => $this->config->username,



More information about the icinga-checkins mailing list