From 8b354adf44e6809c0530ff7e99a6f9db875365e0 Mon Sep 17 00:00:00 2001 From: Nick Liu Date: Sun, 19 Jan 2020 14:33:11 +0100 Subject: [PATCH] Don't spam database server with connections - MOD: Silently ignore failures to e_db_mysql::close(); if it's failing, it's probably already closed - FIX: Close the PDO or mysqli connection after each e_db_abstractTest test - MOD: Changed class2.php's $sql variable to be hinted as an e_db instead of e_db_mysql --- class2.php | 4 ++-- e107_handlers/e_db_pdo_class.php | 10 +++++++--- e107_handlers/mysql_class.php | 3 +-- e107_tests/tests/unit/e_db_abstractTest.php | 17 ++++++++++------- e107_tests/tests/unit/e_db_mysqlTest.php | 2 +- e107_tests/tests/unit/e_db_pdoTest.php | 2 +- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/class2.php b/class2.php index 9b5f985d1..760d24b4e 100755 --- a/class2.php +++ b/class2.php @@ -2,7 +2,7 @@ /* * e107 website system * -* Copyright (C) 2008-2010 e107 Inc (e107.org) +* Copyright (C) 2008-2020 e107 Inc (e107.org) * Released under the terms and conditions of the * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * @@ -391,7 +391,7 @@ e107::getSingleton('e107_traffic'); // We start traffic counting ASAP // e107_require_once(e_HANDLER.'mysql_class.php'); //DEPRECATED, BC, $e107->sql caught by __get() -/** @var e_db_mysql $sql */ +/** @var e_db $sql */ $sql = e107::getDb(); //TODO - find & replace $sql, $e107->sql $sql->db_SetErrorReporting(false); diff --git a/e107_handlers/e_db_pdo_class.php b/e107_handlers/e_db_pdo_class.php index 7535f3c49..3a9a4f77f 100644 --- a/e107_handlers/e_db_pdo_class.php +++ b/e107_handlers/e_db_pdo_class.php @@ -1,8 +1,12 @@ provide_mySQLaccess(); e107::getSingleton('e107_traffic')->BumpWho('db Close', 1); - $result = mysqli_close($this->mySQLaccess); - if ($result === false) $this->dbError('dbClose'); + @mysqli_close($this->mySQLaccess); } diff --git a/e107_tests/tests/unit/e_db_abstractTest.php b/e107_tests/tests/unit/e_db_abstractTest.php index b3d395dd5..a4ec94b45 100644 --- a/e107_tests/tests/unit/e_db_abstractTest.php +++ b/e107_tests/tests/unit/e_db_abstractTest.php @@ -2,7 +2,7 @@ /** * e107 website system * - * Copyright (C) 2008-2019 e107 Inc (e107.org) + * Copyright (C) 2008-2020 e107 Inc (e107.org) * Released under the terms and conditions of the * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * @@ -20,6 +20,14 @@ abstract class e_db_abstractTest extends \Codeception\Test\Unit */ abstract protected function makeDb(); + /** + * Prevent creating too many connections to database server + */ + public function _after() + { + $this->db->close(); + } + protected function loadConfig() { /** @var Helper\DelayedDb $db */ @@ -47,9 +55,6 @@ abstract class e_db_abstractTest extends \Codeception\Test\Unit $this->assertTrue($result); } - - - public function testGetMode() { $actual = $this->db->getMode(); @@ -1006,7 +1011,6 @@ abstract class e_db_abstractTest extends \Codeception\Test\Unit */ public function testSecondaryDatabaseInstance() { - try { $xql = $this->makeDb(); @@ -1128,8 +1132,7 @@ abstract class e_db_abstractTest extends \Codeception\Test\Unit $empty = $xql->isEmpty($table); $this->assertTrue($empty,"isEmpty() or truncate() failed"); - - + $xql->close(); } } diff --git a/e107_tests/tests/unit/e_db_mysqlTest.php b/e107_tests/tests/unit/e_db_mysqlTest.php index ab1b65465..371e085be 100644 --- a/e107_tests/tests/unit/e_db_mysqlTest.php +++ b/e107_tests/tests/unit/e_db_mysqlTest.php @@ -2,7 +2,7 @@ /** * e107 website system * - * Copyright (C) 2008-2018 e107 Inc (e107.org) + * Copyright (C) 2008-2020 e107 Inc (e107.org) * Released under the terms and conditions of the * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * diff --git a/e107_tests/tests/unit/e_db_pdoTest.php b/e107_tests/tests/unit/e_db_pdoTest.php index e09c566af..2755d663f 100644 --- a/e107_tests/tests/unit/e_db_pdoTest.php +++ b/e107_tests/tests/unit/e_db_pdoTest.php @@ -2,7 +2,7 @@ /** * e107 website system * - * Copyright (C) 2008-2018 e107 Inc (e107.org) + * Copyright (C) 2008-2020 e107 Inc (e107.org) * Released under the terms and conditions of the * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *