Skip to content
Snippets Groups Projects
Commit a8eb5567 authored by Olav Morken's avatar Olav Morken
Browse files

consent: Add support for setting the timeout when connecting to the database.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2998 44740490-163a-0410-bde0-09ae8108e29a
parent 408ab4e1
No related branches found
No related tags found
No related merge requests found
...@@ -98,6 +98,9 @@ The `consent:Database` backend storage has the following options ...@@ -98,6 +98,9 @@ The `consent:Database` backend storage has the following options
: Name of the table used for storing the consents. This option is optional : Name of the table used for storing the consents. This option is optional
and defaults to `consent`. and defaults to `consent`.
`timeout`
: The number of seconds to wait for a connection to the database server. This option is optional. If unset, it uses the default from the database-driver.
Example config using PostgreSQL database: Example config using PostgreSQL database:
90 => array( 90 => array(
......
...@@ -39,6 +39,13 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store ...@@ -39,6 +39,13 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store
*/ */
private $_table; private $_table;
/**
* The timeout of the database connection.
*
* @var int|NULL
*/
private $_timeout = NULL;
/** /**
* Database handle. * Database handle.
* *
...@@ -86,6 +93,15 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store ...@@ -86,6 +93,15 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store
$this->_table = 'consent'; $this->_table = 'consent';
} }
if (isset($config['timeout'])) {
if (!is_int($config['timeout'])) {
throw new Exception(
'consent:Database - \'timeout\' is supposed to be an integer.'
);
}
$this->_timeout = $config['timeout'];
}
// @TODO Should be removed // @TODO Should be removed
$db = $this->_getDB(); $db = $this->_getDB();
} }
...@@ -447,9 +463,14 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store ...@@ -447,9 +463,14 @@ class sspmod_consent_Consent_Store_Database extends sspmod_consent_Store
return $this->_db; return $this->_db;
} }
$driver_options = array();
if (isset($this->_timeout)) {
$driver_options[PDO::ATTR_TIMEOUT] = $this->_timeout;
}
// @TODO Cleanup this section // @TODO Cleanup this section
//try { //try {
$this->_db = new PDO($this->_dsn, $this->_username, $this->_password); $this->_db = new PDO($this->_dsn, $this->_username, $this->_password, $driver_options);
// } catch (PDOException $e) { // } catch (PDOException $e) {
// SimpleSAML_Logger::error('consent:Database - Failed to connect to \'' . // SimpleSAML_Logger::error('consent:Database - Failed to connect to \'' .
// $this->_dsn . '\': '. $e->getMessage()); // $this->_dsn . '\': '. $e->getMessage());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment