[Icecast] Icecast2 Status Page Parser
Chris Jones
_+icecast at sucs.org
Fri May 19 11:51:35 UTC 2006
Greg J. Ogonowski wrote:
> Does anyone have a Perl or PHP Icecast2 Status Page Parser?
>
> Thanks.
> -greg.
Any XML parser should do... I have a script which grabs
http://admin:password@server/admin/stats.xml and returns the bits I care
about.
This example uses the Pear XML_Serializer library
(http://pear.php.net/package/XML_Serializer), but if you have PHP5
simplexml will do much the same thing.
Doing it your self using the xml parsing tools inst exactly hard either.
The contents of the XML file are turned into a PHP array $data
<?php
$xml = file("http://admin:password@server/admin/stats.xml");
$xml = $xml[1];
require_once 'Unserializer.php';
// complex structures are arrays, the key is the attribute 'handle'
or 'name', if handle is not present
$options = array(
"complexType" => "array",
"keyAttribute" => array('source' => 'mount')
);
// be careful to always use the ampersand in front of the new
operator
$unserializer = &new XML_Unserializer($options);
// userialize the document
$status = $unserializer->unserialize($xml, false);
if (PEAR::isError($status)) {
echo "Error: " . $status->getMessage();
} else {
$data = $unserializer->getUnserializedData();
}
?>
--
Chris Jones, SUCS Admin
http://sucs.org
More information about the Icecast
mailing list