1
0
Fork 1

Improve logging

pull/22/head
mdPlusPlus 3 years ago
parent 9109aa399d
commit 2b2ede8f1d

@ -101,15 +101,19 @@
// get awesome session group list html // get awesome session group list html
log_info("Requesting Awesome Session Group list."); log_info("Requesting Awesome Session Group list.");
$asgl_html = file_get_contents($asgl); $asgl_html = file_get_contents($asgl);
// log_debug($http_response_header[0]); // Supposed to be "HTTP/1.1 200 OK"
// get lokilocker.com html // get lokilocker.com html
log_info("Requesting Lokilocker Mods Open Group list."); log_info("Requesting Lokilocker Mods Open Group list.");
$ll_html = file_get_contents($ll); $ll_html = file_get_contents($ll);
// log_debug($http_response_header[0]); // Supposed to be "HTTP/1.1 200 OK"
// get session.directory html // get session.directory html
$sd_html = ""; $sd_html = "";
log_info("Requesting session.directory list."); log_info("Requesting session.directory list.");
$sd_pre_html = file_get_contents($sd_pre); $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+/"; $sd_pattern = "/view_session_group_user_lokinet\.php\?id=\d+/";
preg_match_all($sd_pattern, $sd_pre_html, $sd_links); preg_match_all($sd_pattern, $sd_pre_html, $sd_links);
$sd_links = $sd_links[0]; $sd_links = $sd_links[0];
@ -117,7 +121,9 @@
// add prefix "https://session.directory to the sd_links // 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); $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 // add html to sd_html
// log_debug("Requesting " . $link);
$sd_html = $sd_html . file_get_contents($link) . PHP_EOL; $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."); log_info("Done fetching sources.");
@ -180,6 +186,7 @@
* Result is unique and sorted * Result is unique and sorted
*/ */
function reduce_servers($servers_arr) { function reduce_servers($servers_arr) {
log_info("Checking found servers for availability.");
$reduced_servers = array(); $reduced_servers = array();
$offline_servers = array(); // debug $offline_servers = array(); // debug
foreach($servers_arr as $server) { foreach($servers_arr as $server) {
@ -237,6 +244,7 @@
* $room_array arrays contain token, name, users and description * $room_array arrays contain token, name, users and description
*/ */
function query_servers_for_rooms($url_arr) { function query_servers_for_rooms($url_arr) {
log_info("Querying available servers for rooms.");
$rooms = array(); $rooms = array();
$failed_arr = array(); // debug $failed_arr = array(); // debug
@ -265,9 +273,8 @@
$result = array(); $result = array();
$endpoint = "/rooms?all=1"; $endpoint = "/rooms?all=1";
$json_url = $server_url . $endpoint; $json_url = $server_url . $endpoint;
// $json = file_get_contents($json_url);
log_info("Polling $server_url for rooms."); 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("URL: " . $server_url . " - JSON URL: " . $json_url . PHP_EOL);
// echo("JSON: " . $json . PHP_EOL); // echo("JSON: " . $json . PHP_EOL);
$failed = false; $failed = false;

@ -24,4 +24,8 @@
function log_info($msg) { function log_info($msg) {
fwrite(STDERR, "[" . runtime_str() . "] [i] $msg" . PHP_EOL); fwrite(STDERR, "[" . runtime_str() . "] [i] $msg" . PHP_EOL);
} }
function log_debug($msg) {
fwrite(STDERR, "[" . runtime_str() . "] [d] $msg" . PHP_EOL);
}
?> ?>

@ -40,11 +40,11 @@
curl_close($ch); curl_close($ch);
if ($retcode != 0) { if ($retcode != 0) {
// echo($url . " is " . $retcode . PHP_EOL); // log_debug($url . " is " . $retcode . ".");
return true; return true;
} }
else { else {
// echo($url . " is " . $retcode . PHP_EOL); // log_debug($url . " is " . $retcode . ".");
return false; return false;
} }
} }
@ -65,11 +65,11 @@
curl_close($ch); curl_close($ch);
if ($retcode == 200) { if ($retcode == 200) {
// echo($url . " is " . $retcode . PHP_EOL); // log_debug($url . " is " . $retcode . ".");
return true; return true;
} }
else { else {
// echo($url . " is " . $retcode . PHP_EOL); // log_debug($url . " is " . $retcode . ".");
return false; return false;
} }
} }
@ -107,7 +107,7 @@
curl_close($curl); curl_close($curl);
// echo("Trial #" . $counter . " for " . $url . " returned code " . $retcode . PHP_EOL); // log_debug("Trial #" . $counter . " for " . $url . " returned code " . $retcode . ".");
$counter++; $counter++;
sleep($sleep); sleep($sleep);
} }