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:
Guillermo Pages
2026-02-12 23:28:22 +01:00
parent 11579d5170
commit 09d06bc085

View File

@@ -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;