Overview

Server Diagnostics

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.

Source Code

<?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;
?>

Result

<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">[
	{
		&quot;id&quot; : 18011696,
		&quot;path&quot; : &quot;\/examples\/web_server_info_845465_tmp.dws&quot;,
		&quot;query&quot; : &quot;&quot;,
		&quot;ip&quot; : &quot;::1&quot;,
		&quot;ms&quot; : 0,
		&quot;sleeping&quot; : false,
		&quot;options&quot; : [ ]
	},
	{
		&quot;id&quot; : 18011634,
		&quot;path&quot; : &quot;\/test\/index.dws&quot;,
		&quot;query&quot; : &quot;action=update_examples&amp;api=1&quot;,
		&quot;ip&quot; : &quot;::1&quot;,
		&quot;ms&quot; : 1734,
		&quot;sleeping&quot; : false,
		&quot;options&quot; : [ ]
	}
]</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>
  
On this page