Wowza Community

Display current listeners using PHP

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: http://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

How I can create a PHP script to see these statistics without authentication bypass?

Hi, Thanks for the reply,

I’m trying to create an interface to display real time statistics to my client, I can not disable authentication and tried with different authentication methods of PHP like Curl, HttpRequest, file_get_contents and simplexml_load_file, but always returns this error:

“failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized in …”

I do not know why my authentication is not validated…

For example, I trying with:

<?php $page = file_get_contents('http://myuser:mypassword@myservername:myport/connectioncounts'); echo $page; ?>

Thanks for the prompt response,

I am using port 8086.

I have not even changed the file VHost.xml.

However through my browser I can to access the statistics using the URL:

http://myuser:mypassword@MyServerName:MYPORT/connectioncounts

Thanks for your help…

For your method to work, you have to change the /conf/VHost.xml HTTProvider /AuthenticationMethod from “admin-digest” to “admin-basic” or “none”

<HTTPProvider>
	<BaseClass>com.wowza.wms.http.HTTPConnectionCountsXML</BaseClass>
	<RequestFilters>connectioncounts*</RequestFilters>
	<AuthenticationMethod>admin-basic</AuthenticationMethod>
</HTTPProvider>

Then restart Wowza.

Richard

I am having trouble calling [ip]:8086/connectioncounts from any web application. I am able to call it from a browser without an issue.

I have tried the php example and a coldfusion example still I am not able to call the xml file. I can however I can call [ip]:1935/clientaccesspolicy.xml without a problem.

I am on an EC2 machine and have port 8086 and 1935 configured the same way. Any help would be appreciated. Thanks.

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: http://www.wowza.com/forums/showthread.php?15165-get-connectioncounts-from-perl-for-accumulation

Hi Randal,

Thanks for the reply. I have conf/vhost.xml set as below

					<HTTPProvider>
						<BaseClass>com.wowza.wms.http.HTTPConnectionCountsXML</BaseClass>
						<RequestFilters>connectioncounts*</RequestFilters>
						<AuthenticationMethod>none</AuthenticationMethod>
					</HTTPProvider>

and can confirm from multiple devices that from the browser i do not have to input username and password to access.

I have tried the php, perl and coldfusion code and the response I get is timeouts of (php)“Maximum execution time of 45 seconds exceeded” and (cf)“Connection Failure”

I feel like I am missing something fundamental here but cannot figure it out. Thanks for the help.

Hi…Solved.

Come to find out my host was blocking port 8086. So I changed the port in vhost and now all is well.

Hello All

Need help trying to return Stats for a single application under 1 VHOST

Here’s a step by step process to get stats with basic authentication WITH php code to answer the original question:

  1. In your wowza install in conf/Vhost.xml change the values of admin-digest to admin-basic for whatever HTTPProvider you want to authenticate for. I changed them all to “basic” because I need to report for everything available.

  2. Use this PHP code to test for your server

<?php header("Content-type: text/xml; charset=utf-8"); // username and password for reporting are created in Wowzainstall/conf/admin.password $wowzaurl = "http://localhost:8086/connectioncounts"; $username = "username"; $password = "password"; //header wowza expects for basic authentication - base 64 encoded. $context = stream_context_create(array( 'http' => array( 'header' => "Authorization: Basic " . base64_encode("".$username.":".$password."") ) )); //get contents with sending the special header into an xml file $WowzaMediaServer = simplexml_load_string(file_get_contents($wowzaurl,false,$context)); //print XML result print_r($WowzaMediaServer); exit; ?>