Snippets v2

Languages
My Snippets

Apache Status in XML using PHP Login or Register to Bookmark this snippet

Description PHP

This scripts displays Apache 2.0.x server status information and formats the data into an XML document.

The Code Download
  1. <?php
  2. // phpExamples.net (http://phpexamples.net)  
  3. // Author: Rob Burris ( robeb@phpexamples.net
  4. //
  5. // This scripts displays Apache 2.0.x server  
  6. // status information and formats the data into
  7. // an XML document.                              
  8.  
  9. // Machine readable server status URL.
  10. $url = "http://localhost/server-status?auto";
  11.  
  12. $dataArray = file($url);
  13.  
  14. // Use the metadata as the key and the data as the element (i.e. BusyWorkers => 2).
  15. foreach($dataArray as $k => $v) {
  16.    $v = str_replace(' ','',$v);
  17.    $infoArray = explode(':',$v);
  18.    $outputArray[$infoArray[0]] = $infoArray[1];
  19. };
  20.  
  21. // Format the data into a nice XML document where the keys become elements.
  22. echo "<?xml version="1.0" encoding="ISO-8859-1" ?>n";
  23. echo "<apacheStatus>\n";
  24. foreach($outputArray as $k => $v) {
  25. // We don't want Scoreboard because it skews the XML document.
  26.    if ($k == "Scoreboard") {
  27.        echo "</apacheStatus>\n";
  28.        exit;
  29.    }
  30.    echo " <".$k.">".$v."</".$k.">\n";
  31.     };
  32. echo "</apacheStatus>\n";
  33. ?>
Credits Contact JC

Added by JC on 11th November, 2007

Comments

There are no comments about this snippet.

Post Comment HTML is allowed

You must be registered and logged in to post a comment.

Login here to post a comment