Created
August 27, 2014 17:25
-
-
Save iamcal/6b1b37897758f83368a4 to your computer and use it in GitHub Desktop.
Parse mod_status output for localhost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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