Display current listeners using PHP

Here’s one that goes thru the connectioncounts and presents some info about the apps & streams. Also shows current outbound bitate for the server & apps.

[PHP]

<?php $hostname = "YOURWOWZAHOSTNAMEHERE.COM"; $xml_data=file_get_contents("http://$hostname:8086/connectioncounts"); $doc = new DOMDocument(); $doc->loadXML($xml_data); $wms = $doc->getElementsByTagName('WowzaMediaServer'); $wmstotalactive = $wms->item(0)->getElementsByTagName("ConnectionsCurrent")->item(0)->nodeValue; $wmstotaloutbytes = $wms->item(0)->getElementsByTagName("MessagesOutBytesRate")->item(0)->nodeValue; $wmstotaloutbits = $wmstotaloutbytes * '8'; echo "Hostname: $hostname

Server Total Active Connections: $wmstotalactive
Total Outbo und bitrate: $wmstotaloutbits

"; $wmsapp = $doc->getElementsByTagName('Application'); $wmscnt = $wmsapp->length; echo "Applications"; for ($idx = 0; $idx < $wmscnt; $idx++) { $appname = $wmsapp->item($idx)->getElementsByTagName("Name")->item(0)->nodeValue; $appccount = $wmsapp->item($idx)->getElementsByTagName("ConnectionsCurrent")->item(0)->nodeValue; $appoutbytes = $wmsapp->item($idx)->getElementsByTagName("MessagesOutBytesRate")->item(0)->nodeValue; $appoutbits = $appoutbytes * '8'; echo "
Application Name: $appname
Active Connections: $appccount
Application Bits Out: $appoutbits
"; } echo "
Streams"; $wmsast = $doc->getElementsByTagName('Stream'); $wmsasct = $wmsast->length; for ($sidx = 0; $sidx < $wmsasct; $sidx++) { $strname = $wmsast->item($sidx)->getElementsByTagName("Name")->item(0)->nodeValue; $strctot = $wmsast->item($sidx)->getElementsByTagName("SessionsTotal")->item(0)->nodeValue; echo "
Stream URL: $strname
Connections to Stream: $strctot
"; } ?>

[/PHP]

For an easier way to get info on just 1 VHost, you can use the original script and just break out of a loop when you find the one you want (Poor man’s single VHost info :wink: )

Here’s my code I wrote from scratch, similar to the first post but it uses PHP’s simpleXML and I am looping through the vhosts. This way you can get info on 1 stream (although you still have to download all vhost info before you can get it)

<?php
// Get connection counts for all vhosts; print single VHost info
$url = 'http://MYHOST:8086/connectioncounts';
$page = simplexml_load_file($url);
/*
echo '<pre>';
print_r($page);
echo '</pre>';
*/
// All VHosts in an array
$vhosts = $page->VHost;
// Loop through each VHost
foreach($vhosts as $vh)
{
    $vh_name          = $vh->Name;
    $vh_conn_cur      = $vh->ConnectionsCurrent;
    $vh_conn_accepted = $vh->ConnectionsTotalAccepted;
    $vh_conn_rejected = $vh->ConnectionsTotalRejected;
    if($vh_name == 'coolVhost')
    {
        break;
    }
}
// JSON Output for portability
echo '{"current":"' . $vh_conn_cur . '","accepted":"' . $vh_conn_accepted . '","rejected":"' . $vh_conn_rejected . '"}';
?>

If there is any more info on an easy way how to get info on just 1 vhost and NOT all Vhosts’s at once, I am all ears! The current method takes roughly 3 seconds on my server to get info on all vhosts.

I think he means he wants to have to authenticate instead of it just openly giving him the info.

IF that’s what he means, you said it earlier:

…I think you also have to change the connectioncounts HTTProvider in /conf/VHost.xml from “admin-digest” to “none”

If he makes the HTTProvider for connectioncounts back to “admin-digest”, it should try and authenticate. Then using PHP, instead of using “$page = simplexml_load_file($url);”, you’d use CURL and authenticate with a regular auth. Then just use simplexml_load_string().

Hi guys !!

What about people who is using Wowza Media Server Pro Unlimited 1.7.2 build12107

Like me !!

Thks a lot

Hi guys !!

What about people who is using Wowza Media Server Pro Unlimited 1.7.2 build12107

Like me !!

Thks a lot

interesting post, but how do you specify each stream in the php file? cause this will count all the connections to the server and not to a specify application or stream.

which code should I use?

Is there a way to get the xml file without using allow_fopen_url ??

Hi Christr,

Thanks, Great Code! I tried it on my server but its only showing the wowza version, I guess I need to modify some settings on the vhost.xml

http://[wowza_server]:8086/connectioncounts needs a username and password, what HTTP header should I send to pass the certification.

I get following by wireshark, but I don’t know how to encode my username and password:

Authorization: Digest username="admin",realm="Wowza Media Systems",nonce="957049024554bf2babf48a5467e52eec",uri="/connectioncounts",cnonce="d3b895b0d8dbc7e1e7b4a545d3e2504b",nc=00000006,algorithm=MD5,response="bd13373e2aa9218fe617221448e620b7",qop="auth"

I know how to set username and password in wowza configuartion file admin.passwd. I want pass the certification in my PHP code to get information I want automatically.

The following is what I did now.

I send a HTTP Header like ‘"Authorization: Basic ".base64_encode(“myusername:mypassword”)’ to ‘http://[wowza-server]:8086/connectioncounts’,

but the server return the following ‘401 Unauthorized WWW-Authenticate’ to me, why?

the following is the message wowza server returned.

HTTP/1.1 401 Unauthorized WWW-Authenticate: Digest realm=“Wowza Media Systems”, nonce=“144ea174648e736919a83bde8dc12d91”, algorithm=MD5, qop=“auth” Content-Type: text/html Connection: Keep-Alive Server: FlashCom/3.5.2 Cache-Control: no-cache Content-Length: 0

I see, wms require a Digest HTTP certification.

Hi,

This could be made without disable the digest authentication on the wowza vhost server?

Can we changue the connectioncounts* to another private location?

Disable that will show applications name and private info to everyone…

Can this xml show ips conected?

Thanks you.

Hi,

This has been solved changue to none the Vhost and changue name to another private name.

Now I can´t take more than one IP on the PHP you give us.

Any solution? 8086/serverinfo shows IP but the php show only one.

Thanks you.

Solved.

To show IPs per application just add:

$wmsapp = $doc->getElementsByTagName(‘Client’);

$wmscnt = $wmsapp->length;

You can get the IP, the Client, and the referrer.

Great to offer stats to my costumers of videostream.

Thanks you.

Probably because clientaccesspolicy doesn’t require authentication. Where you able to turn off authentication so you can access connection counts without the password prompt? Remember, if you put in your credentials in your browser one time, it doesn’t ask you again until you restart Wowza.

I posted a Perl script here to get connectioncounts: https://www.wowza.com/forums/showthread.php?15165-get-connectioncounts-from-perl-for-accumulation

Hey there,

I am having problems with this code (the connectioncounts XML parser), I have implemented the code exactly as told at the start of this topic, but when I go to the page, it returns the following PHP error:

Warning: DOMDocument::loadXML() [domdocument.loadxml]: Empty string supplied as input in /home/site/public_html/tv/test.php on line 6

Fatal error: Call to a member function getElementsByTagName() on a non-object in /home/site/public_html/tv/test.php on line 9

The PHP code is as follows:

[PHP]

<?php $xml_data=file_get_contents("http://url:5800/connectioncounts"); $doc = new DOMDocument(); $doc->loadXML($xml_data); $wms = $doc->getElementsByTagName('WowzaMediaServer'); $currentlistener = $wms->item(0)->getElementsByTagName("ConnectionsCurrent")->item(0)->nodeValue; $listenerhits = $wms->item(0)->getElementsByTagName("ConnectionsTotal")->item(0)->nodeValue; echo "Current listener: $currentlistener
Total hits: $listenerhits"; ?>

[/PHP]

I can access the connectioncounts xml page directly through my web browser, but the script will not. I have no authentication required to access the page and I have also tried changing “loadXML()” to “load()”, which just returns even more PHP errors.

Any help on this matter would be greatly appreciated. :slight_smile:

I see than the port is 5800, are your changed the default admin port into the VHost.xml? and do you have the php-xml extension installed into your server?

Yes I have changed the default port in the VHost file. Like I said, I can access the page directly by putting in the URL all fine.

As for the php-xml extension, what do you mean? Those functions are PHP standard. I am running the latest version of PHP and have “php_xsl” enabled in my php.ini.

I’m still having problems with the script. I changed the ‘connectioncounts’ port back to 8086, but i still get the following error. I can definately access the xml file directly through my browser, by going to “http://[myserverip]:8086/connectioncounts” but it simply won’t work in php. I checked my PHP config and all XML functions are enabled, yet it still returns this error. I am using no authentication either, so it should work.

Warning: DOMDocument::loadXML() [domdocument.loadxml]: Empty string supplied as input in /home/root/public_html/response.php on line 8

Fatal error: Call to a member function getElementsByTagName() on a non-object in /home/root/public_html/response.php on line 11

I have no idea what is happening. I’ll post my current code for you again.

[PHP]

<?php $xml_data=file_get_contents("http://[myserverip]:8086/connectioncounts"); $doc = new DOMDocument(); $doc->loadXML($xml_data); $wms = $doc->getElementsByTagName('WowzaMediaServer'); $currentlistener = $wms->item(0)->getElementsByTagName("ConnectionsCurrent")->item(0)->nodeValue; $listenerhits = $wms->item(0)->getElementsByTagName("ConnectionsTotal")->item(0)->nodeValue; echo "Current listener: $currentlistener
Total hits: $listenerhits"; ?>

[/PHP]

Any more help would be really appreciated.

Try using double quotes on line 8:

 $wms = $doc->getElementsByTagName("WowzaMediaServer"); 

Richard

I made the corrections but it still returns the same error. :frowning:

I think you also have to change the connectioncounts HTTProvider in /conf/VHost.xml from “admin-digest” to “none”

Otherwise, I’m not sure. I’ve not used this.

Richard

I have already set the VHost file to “none”. Thanks for your help anyways… ponders