Illustrates runtime server introspection using the 'WebServer' object. This example demonstrates how to programmatically retrieve active server configuration, monitor live database queries via JSON status dumps, and inspect the compiled program cache for performance monitoring and troubleshooting.
<?pas
uses System.WebServer, Security;
CheckLocalhostAccess;
?>
<h3>WebServer Information</h3>
<ul>
<li><b>Server Name:</b> <?pas= WebServer.Name.ToHtml ?></li>
<li><b>HTTP Port:</b> <?pas= if WebServer.HttpPort <> 0 then 'Active' else 'Inactive' ?></li>
<li><b>HTTPS Port:</b> <?pas= if WebServer.HttpsPort <> 0 then 'Active' else 'Inactive' ?></li>
</ul>
<h3>Active Sessions / Queries</h3>
<pre class="bg-body-tertiary p-3 border rounded"><?pas
var queries := JSON.Parse(WebServer.LiveQueries);
Print(JSON.PrettyStringify(queries).ToHtml);
?></pre>
<h3>Compiled Programs (Top 5)</h3>
<?pas
var programs := WebServer.CompiledPrograms;
if programs.Length > 0 then begin
?>
<ul>
<?pas
for var i := 0 to Min(programs.Length, 5) - 1 do begin
var progName := programs[i];
if Pos('\', progName) > 0 then
progName := progName.AfterLast('\');
PrintLn(#9'<li>' + progName.ToHtml + '</li>');
end;
?>
</ul>
<?pas
end else begin
?><p>No programs currently in cache.</p><?pas
end;
?>
<h3>WebServer Information</h3>
<ul>
<li><b>Server Name:</b> DWScript</li>
<li><b>HTTP Port:</b> Active</li>
<li><b>HTTPS Port:</b> Inactive</li>
</ul>
<h3>Active Sessions / Queries</h3>
<pre class="bg-body-tertiary p-3 border rounded">[
{
"id" : 18011696,
"path" : "\/examples\/web_server_info_845465_tmp.dws",
"query" : "",
"ip" : "::1",
"ms" : 0,
"sleeping" : false,
"options" : [ ]
},
{
"id" : 18011634,
"path" : "\/test\/index.dws",
"query" : "action=update_examples&api=1",
"ip" : "::1",
"ms" : 1734,
"sleeping" : false,
"options" : [ ]
}
]</pre>
<h3>Compiled Programs (Top 5)</h3>
<ul>
<li>assoc_iteration.dws</li>
<li>attribute_validation.dws</li>
<li>json_demo.dws</li>
<li>sqlite_basics.dws</li>
<li>math_biginteger_demo_653454_tmp.dws</li>
</ul>