From de28d85a71a0020093fb0b7e96e04c9225fd747b Mon Sep 17 00:00:00 2001 From: ghost Date: Sat, 5 Aug 2023 19:39:49 +0300 Subject: [PATCH] add connection exceptions --- crontab/cleaner.php | 11 ++++++++++- crontab/crawler.php | 2 +- public/api.php | 34 ++++++++++++++++++++++++++++++---- public/file.php | 10 +++++++++- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/crontab/cleaner.php b/crontab/cleaner.php index 5e12b81..d164d75 100644 --- a/crontab/cleaner.php +++ b/crontab/cleaner.php @@ -26,7 +26,16 @@ require_once(__DIR__ . '/../config/app.php'); require_once(__DIR__ . '/../library/mysql.php'); // Connect database -$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); +try { + + $db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); + +} catch(Exception $e) { + + var_dump($e); + + exit; +} // Reset banned hosts $hostsBansRemoved = $db->resetBannedHostPages(time() - CLEAN_HOST_PAGE_BAN_SECONDS_OFFSET); diff --git a/crontab/crawler.php b/crontab/crawler.php index 245b39a..a8e2137 100644 --- a/crontab/crawler.php +++ b/crontab/crawler.php @@ -1048,4 +1048,4 @@ echo 'HTTP Requests total size: ' . $httpRequestsSizeTotal . PHP_EOL; echo 'HTTP Download total size: ' . $httpDownloadSizeTotal . PHP_EOL; echo 'HTTP Requests total time: ' . $httpRequestsTimeTotal . PHP_EOL . PHP_EOL; -echo 'Total time: ' . $executionTimeTotal . PHP_EOL . PHP_EOL; +echo 'Total time: ' . $executionTimeTotal . PHP_EOL . PHP_EOL; \ No newline at end of file diff --git a/public/api.php b/public/api.php index 8014212..628ac04 100644 --- a/public/api.php +++ b/public/api.php @@ -19,12 +19,29 @@ if (API_ENABLED) { if (API_SEARCH_ENABLED) { + // Connect Sphinx search server + try { + + $sphinx = new SphinxQL(SPHINX_HOST, SPHINX_PORT); + + } catch(Exception $e) { + + var_dump($e); + + exit; + } + // Connect database - $db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); + try { - // Connect Sphinx search server - $sphinx = new SphinxQL(SPHINX_HOST, SPHINX_PORT); + $db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); + } catch(Exception $e) { + + var_dump($e); + + exit; + } // Filter request data $type = !empty($_GET['type']) ? Filter::url($_GET['type']) : 'text'; @@ -77,7 +94,16 @@ if (API_ENABLED) { if (API_HOSTS_ENABLED) { // Connect database - $db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); + try { + + $db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); + + } catch(Exception $e) { + + var_dump($e); + + exit; + } $response = [ 'status' => true, diff --git a/public/file.php b/public/file.php index 3525929..8fc7a57 100644 --- a/public/file.php +++ b/public/file.php @@ -44,8 +44,16 @@ switch ($type) { case 'snap': // Connect database - $db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); + try { + $db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); + + } catch(Exception $e) { + + var_dump($e); + + exit; + } // Init request $crc32ip = crc32(!empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '');