Skip to content

Instantly share code, notes, and snippets.

@iamcal
Created August 27, 2014 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamcal/6b1b37897758f83368a4 to your computer and use it in GitHub Desktop.
Save iamcal/6b1b37897758f83368a4 to your computer and use it in GitHub Desktop.
Parse mod_status output for localhost
<?php
#
# scoreboard stuff
#
echo file_get_contents('http://localhost/server-status?auto');
echo "\n";
#
# get child status
#
$xml = file_get_contents('http://localhost/server-status');
#echo "XML: ".strlen($xml)."\n";
$dom = new DomDocument();
$dom->strictErrorChecking = false;
$dom->loadHTML($xml);
$table = $dom->getElementsByTagName('table')->item(0);
$out = array();
foreach ($table->childNodes as $row){
if ($row->nodeName != 'tr') continue;
$out_row = array();
foreach ($row->childNodes as $cell){
if ($cell->nodeName != 'td' && $cell->nodeName != 'th') continue;
$out_row[] = trim($cell->textContent);
}
$out[] = $out_row;
}
#echo "Reached bottom?\n";
#print_r($out);
$fh = fopen('php://output', 'w');
foreach ($out as $row){
fputcsv($fh, $row);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment