fix: add persistent connections + fix self::$pdo bug
- Add PDO::ATTR_PERSISTENT to prevent SQL Server connection storms under concurrent PHP-FPM load (was causing 241 SQLSTATE[08001] failures/day on callioapi) - Fix bug: $pdo → self::$pdo in connect() and getPDOInstance() guards (was checking undefined local var instead of static prop)
This commit is contained in:
@@ -35,16 +35,16 @@ class PDOWithFilters {
|
||||
|
||||
|
||||
public static function connect($dsn, $username, $password) {
|
||||
if (!empty($pdo)) {
|
||||
if (!empty(self::$pdo)) {
|
||||
throw new \Exception('Create Pdo only once');
|
||||
}
|
||||
self::$pdo = new \PDO($dsn, $username, $password);
|
||||
self::$pdo = new \PDO($dsn, $username, $password, [\PDO::ATTR_PERSISTENT => true]);
|
||||
|
||||
return self::$pdo;
|
||||
}
|
||||
|
||||
public static function getPDOInstance() {
|
||||
if (empty($pdo)) {
|
||||
if (empty(self::$pdo)) {
|
||||
throw new \Exception('You must call connect() first');
|
||||
}
|
||||
return self::$pdo;
|
||||
|
||||
Reference in New Issue
Block a user