1
0
Fork 1

Improve logging

pull/17/head
gravel 1 year ago
parent 43660d89c3
commit 0789687479
Signed by: gravel
SSH Key Fingerprint: SHA256:p4HP49CCk4YQMkJpWJ09L8peEPQWjERtdCRAFxPfbOY

@ -7,6 +7,8 @@
$TEMPLATES_ROOT="$PROJECT_ROOT/sites";
$LANGUAGES_ROOT="$PROJECT_ROOT/languages";
include_once "$PROJECT_ROOT/php/utils/logging.php";
// set timeout for file_get_contents()
ini_set('default_socket_timeout', 6); // in seconds, default is 60
@ -16,6 +18,6 @@
// do not report warnings (timeouts, SSL/TLS errors)
error_reporting(E_ALL & ~E_WARNING);
date_default_timezone_set('UTC');
?>

@ -80,7 +80,8 @@
// write output to disk
global $output;
file_put_contents($output, json_encode($info_arrays)); // overwrites existing file
echo("Done. " . count($info_arrays) . " unique Session Communities on " . count_servers($info_arrays) . " servers have been found." . PHP_EOL);
log_info("Done. ");
log_info(Found . count($info_arrays) . " unique Session Communities on " . count_servers($info_arrays) . " servers." . PHP_EOL);
}
/*
@ -96,13 +97,16 @@
$sd_pre = "https://session.directory/?all=groups" ; // this one has to be expanded first
// get awesome session group list html
log_info("Requesting Awesome Session Group list.");
$asgl_html = file_get_contents($asgl);
// get lokilocker.com html
log_info("Requesting Lokilocker Mods Open Group list.");
$ll_html = file_get_contents($ll);
// get session.directory html
$sd_html = "";
log_info("Requesting session.directory list.");
$sd_pre_html = file_get_contents($sd_pre);
$sd_pattern = "/view_session_group_user_lokinet\.php\?id=\d+/";
preg_match_all($sd_pattern, $sd_pre_html, $sd_links);
@ -114,8 +118,10 @@
$sd_html = $sd_html . file_get_contents($link) . PHP_EOL;
}
log_info("Done fetching sources.");
// merge all html into a single string
return(
return (
$asgl_html . PHP_EOL .
$ll_html . PHP_EOL .
$sd_html . PHP_EOL
@ -258,6 +264,7 @@
$endpoint = "/rooms";
$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
// echo("URL: " . $server_url . " - JSON URL: " . $json_url . PHP_EOL);
// echo("JSON: " . $json . PHP_EOL);
@ -267,6 +274,7 @@
$json_rooms = array();
// if response was not empty
if($json_obj) {
log_info("Received response from $server_url.");
foreach($json_obj as $json_room) {
$token = $json_room->token; // room "name"
$users_per_second = $json_room->active_users / $json_room->active_users_cutoff;
@ -307,6 +315,7 @@
if($legacy_rooms) {
$result = $legacy_rooms;
} else {
log_info("Failed to receive response from $server_url.");
$result = null;
}
}

@ -19,8 +19,10 @@
// Do not render auxilliary PHP files.
if (str_contains("$phppath", "/+") || $phppath[0] == "+")
continue;
$docpath = str_replace($TEMPLATES_ROOT, $DOCUMENT_ROOT, $phppath);
$relpath = str_replace($TEMPLATES_ROOT, "", $phppath);
$docpath = str_replace(".php", ".html", $docpath);
// This works? Yes, yes it does.
@ -28,8 +30,11 @@
// otherwise we could include the documents in an ob_* wrapper.
// Same as shell_exec, except we don't have to escape quotes.
log_info("Generating output for $relpath.");
$document = `cd "$TEMPLATES_ROOT"; php $phppath`;
file_put_contents($docpath, $document);
}
log_info("Done generating HTML.");
?>

@ -1,8 +1,3 @@
Running, please wait...
This script will usually take approximately 4 minutes to run.
It will take longer if the Chinese servers are spasming out
or if you are running this for the first time.
<?php
require_once 'fetch-servers.php';
require_once 'generate-html.php';

@ -0,0 +1,27 @@
<?php
$hrtime_start = hrtime();
$NANOSEC = 1E9;
/**
* Calculate process runtime as [s, ns].
*/
function hrtime_interval() {
global $hrtime_start, $NANOSEC;
list($s, $ns) = hrtime();
list($s0, $ns0) = $hrtime_start;
// Borrow
if ($ns < $ns0) { $s--; $ns += $NANOSEC; }
return [$s - $s0, $ns - $ns0];
}
function runtime_str() {
list($s, $ns) = hrtime_interval();
return
date('i:s.', $s) .
str_pad(intdiv($ns, 1E6), 3, "0", STR_PAD_LEFT);
}
function log_info($msg) {
fwrite(STDERR, "[" . runtime_str() . "] [i] $msg" . PHP_EOL);
}
?>

@ -21,6 +21,7 @@
return base64_encode(file_get_contents($png_cached));
}
// fwrite(STDERR, "QR code NOT found for " . $room_id . PHP_EOL);
log_info("Fetching QR code for $room_id.");
$png = file_get_contents(room_invite_png($room_id, $room));
file_put_contents($png_cached, $png);
return base64_encode($png);