From 6e4f39b847d1cc677f8c19f8090944b9390d996e Mon Sep 17 00:00:00 2001 From: mdPlusPlus Date: Sat, 11 Feb 2023 15:08:49 +0100 Subject: [PATCH] Improve logging --- php/fetch-servers.php | 11 +++++++++-- php/utils/logging.php | 6 +++++- php/utils/server-utils.php | 10 +++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/php/fetch-servers.php b/php/fetch-servers.php index 17069ae..fdb9cc6 100644 --- a/php/fetch-servers.php +++ b/php/fetch-servers.php @@ -101,15 +101,19 @@ // get awesome session group list html log_info("Requesting Awesome Session Group list."); $asgl_html = file_get_contents($asgl); +// log_debug($http_response_header[0]); // Supposed to be "HTTP/1.1 200 OK" // get lokilocker.com html log_info("Requesting Lokilocker Mods Open Group list."); $ll_html = file_get_contents($ll); +// log_debug($http_response_header[0]); // Supposed to be "HTTP/1.1 200 OK" // get session.directory html $sd_html = ""; log_info("Requesting session.directory list."); $sd_pre_html = file_get_contents($sd_pre); +// log_debug($http_response_header[0]); // Supposed to be "HTTP/1.1 200 OK" + $sd_pattern = "/view_session_group_user_lokinet\.php\?id=\d+/"; preg_match_all($sd_pattern, $sd_pre_html, $sd_links); $sd_links = $sd_links[0]; @@ -117,7 +121,9 @@ // add prefix "https://session.directory to the sd_links $link = str_replace('view_session_group_user_lokinet.php?id=', 'https://session.directory/view_session_group_user_lokinet.php?id=', $link); // add html to sd_html +// log_debug("Requesting " . $link); $sd_html = $sd_html . file_get_contents($link) . PHP_EOL; +// log_debug($http_response_header[0]); // Supposed to be "HTTP/1.1 200 OK" } log_info("Done fetching sources."); @@ -180,6 +186,7 @@ * Result is unique and sorted */ function reduce_servers($servers_arr) { + log_info("Checking found servers for availability."); $reduced_servers = array(); $offline_servers = array(); // debug foreach($servers_arr as $server) { @@ -237,6 +244,7 @@ * $room_array arrays contain token, name, users and description */ function query_servers_for_rooms($url_arr) { + log_info("Querying available servers for rooms."); $rooms = array(); $failed_arr = array(); // debug @@ -265,9 +273,8 @@ $result = array(); $endpoint = "/rooms?all=1"; $json_url = $server_url . $endpoint; -// $json = file_get_contents($json_url); log_info("Polling $server_url for rooms."); - $json = curl_get_contents($json_url); // circumvents flaky routing + $json = curl_get_contents($json_url); // circumvents flaky routing, don't use file_get_contents // echo("URL: " . $server_url . " - JSON URL: " . $json_url . PHP_EOL); // echo("JSON: " . $json . PHP_EOL); $failed = false; diff --git a/php/utils/logging.php b/php/utils/logging.php index 7683e78..08bdbc2 100644 --- a/php/utils/logging.php +++ b/php/utils/logging.php @@ -24,4 +24,8 @@ function log_info($msg) { fwrite(STDERR, "[" . runtime_str() . "] [i] $msg" . PHP_EOL); } -?> \ No newline at end of file + + function log_debug($msg) { + fwrite(STDERR, "[" . runtime_str() . "] [d] $msg" . PHP_EOL); + } +?> diff --git a/php/utils/server-utils.php b/php/utils/server-utils.php index 8623cf7..72dd56a 100644 --- a/php/utils/server-utils.php +++ b/php/utils/server-utils.php @@ -40,11 +40,11 @@ curl_close($ch); if ($retcode != 0) { -// echo($url . " is " . $retcode . PHP_EOL); +// log_debug($url . " is " . $retcode . "."); return true; } else { -// echo($url . " is " . $retcode . PHP_EOL); +// log_debug($url . " is " . $retcode . "."); return false; } } @@ -65,11 +65,11 @@ curl_close($ch); if ($retcode == 200) { -// echo($url . " is " . $retcode . PHP_EOL); +// log_debug($url . " is " . $retcode . "."); return true; } else { -// echo($url . " is " . $retcode . PHP_EOL); +// log_debug($url . " is " . $retcode . "."); return false; } } @@ -107,7 +107,7 @@ curl_close($curl); -// echo("Trial #" . $counter . " for " . $url . " returned code " . $retcode . PHP_EOL); +// log_debug("Trial #" . $counter . " for " . $url . " returned code " . $retcode . "."); $counter++; sleep($sleep); }