Skip to content

Commit

Permalink
Ensure timeout set upon connection creation
Browse files Browse the repository at this point in the history
  • Loading branch information
eddmann committed Jan 19, 2022
1 parent ceea097 commit 3aa61ba
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions runtime/lib/Propel.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,16 +683,17 @@ public static function initConnection($conparams, $name, $defaultClass = Propel:
}

try {
$con = new $classname($dsn, $user, $password, $driver_options);
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$con->setAttribute(PropelPDO::PROPEL_ATTR_CONNECTION_NAME, $name);

// With the PropelBundle Symfony integration there is no way to correctly specify PDO attributes.
// The configuration schema requires a scalar value, however Propel requires a keyed 'value' array.
// This allows us to specify the timeout within the runtime environment (i.e for Lambda).
if ($connectionTimeout = \getenv('PROPEL_PDO_CONNECTION_TIMEOUT')) {
$con->setAttribute(\PDO::ATTR_TIMEOUT, $connectionTimeout);
$driver_options[\PDO::ATTR_TIMEOUT] = $connectionTimeout;
$driver_options[\PDO::ATTR_ERRMODE] = \PDO::ERRMODE_EXCEPTION;
}

$con = new $classname($dsn, $user, $password, $driver_options);
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$con->setAttribute(PropelPDO::PROPEL_ATTR_CONNECTION_NAME, $name);
} catch (PDOException $e) {
throw new PropelException("Unable to open PDO connection", $e);
}
Expand Down

0 comments on commit 3aa61ba

Please sign in to comment.