Wowza Community

Display current listeners using PHP

Hi,

Here is a simple PHP code to retrieve number of listeners on your stream or connected user.

[PHP]

<?php $xml_data=file_get_contents("http://YOURSERVERIP: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]

To use the code above you need to disable the digest authentication on the wowza vhost server, to do this just edit the Vhost.xml at conf folder and set the AuthenticationMethod to none, save and restart your wowza server

[HTML]

com.wowza.wms.http.HTTPConnectionCountsXML

connectioncounts*

none

[/HTML]

Here’s a quick modify to the above code to do the same thing for your load balancer. This will present some of the useful XML from the load balancer status page in a quick and easy to read format.

[PHP]

<?php $xml_data=file_get_contents("http://YOURWOWZASERVER.com:1935//loadbalancer?serverInfoXML"); $doc = new DOMDocument(); $doc->loadXML($xml_data); $wms = $doc->getElementsByTagName('LoadBalancerServer'); $wmscnt = $wms->length; $conntot = 0; for ($idx = 0; $idx < $wmscnt; $idx++) { $loadbalip = $wms->item($idx)->getElementsByTagName("redirect")->item(0)->nodeValue; $actstatus = $wms->item($idx)->getElementsByTagName("status")->item(0)->nodeValue; $conncnt = $wms->item($idx)->getElementsByTagName("connectCount")->item(0)->nodeValue; $conntot = $conntot + $conncnt; echo "Load Bal IP: $loadbalip
Status: $actstatus
Active Connections: $conncnt

"; } echo "
Total Connections: $conntot
"; ?>[/PHP]

enjoy,

–Chris

How to use the above code to query just 1 Stream Name

Hi,

Here is a simple PHP code to retrieve number of listeners on your stream or connected user.

[PHP]

<?php $xml_data=file_get_contents("http://YOURSERVERIP: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]

To use the code above you need to disable the digest authentication on the wowza vhost server, to do this just edit the Vhost.xml at conf folder and set the AuthenticationMethod to none, save and restart your wowza server

[HTML]

com.wowza.wms.http.HTTPConnectionCountsXML

connectioncounts*

none

[/HTML]

In Wowza 2.1 we also support basic authentication as well. You will see this as an option in conf/Authentication.xml. So you can set the AuthenticationMethod to admin-basic and set the username/password in the header of the HTTP request. It just uses standard basic authentication. The headers looks like this:

Authorization: Basic QWRtaW46Zm9vYmFy

Where QWRtaW46Zm9vYmFy is the Base64 result of [username]:[password].

Charlie

It is best to upgrade to the most recent version. The upgrade process is covered here:

http://www.wowza.com/tradeup.html

Charlie

Set the username and password in /conf/admin.password file

Richard

You can change AuthenticationMethod to “none” in the /conf/VHost.xml file. Find this HTTProvider:

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

Change to:

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

Richard

There is source code for you can modify to your needs:

http://www.wowza.com/community/t/-/84

Richard

Try using double quotes on line 8:

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

Richard

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

You would have to modify the connectioncounts (an HTTProvider) source to handle a querystring or form variable and filter on a stream name.

https://www.wowza.com/docs/how-to-get-connection-counts-for-server-applications-application-instances-and-streams-with-an-http-provider

See this article also:

https://www.wowza.com/docs/how-to-parse-post-or-get-variables-in-an-http-provider

You need the Wowza IDE:

http://wowza.com/ide.html

Richard

What do you mean? How do you want it to work?

Richard

VHost.xml file. Post between code tags.

Which port are you using? There are two HostPort blocks in the default /conf/VHost.xml file.

Did you restart Wowza after changes to VHost.xml?

Richard

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

You can enable Application level logging in /conf/log4j.properties file (look for commented out section).

You can real-time stats from connectioncounts, but for all applications

https://www.wowza.com/docs/how-to-monitor-server-connections-load-and-application-statistics

Richard

The 2nd link I meant to be this

https://www.wowza.com/docs/how-to-monitor-server-connections-load-and-application-statistics

Cool. Thanks.

Richard

Xiaoqing Li,

Can you provide one example about how you pass the Header to Wowza?

You are using PHP?

Thanks,

Alejandro

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?

Hi,

Are you using the load balancer code? The stuff I posted only works on the loadbalancer machine itself. If you hit: http://YOURHOST:1935//loadbalancer?serverInfoXML you should get something that looks like:

0

RUNNING

0

147 milliseconds

123.123.123.123

e062d-9da8-4532-8d87-eaea6894b

2

RUNNING

0

2 seconds 283 milliseconds

123.123.123.122

6dd6e8-742f-4399-88f-573ac9957

1

RUNNING

0

2 seconds 291 milliseconds

123.123.123.111

435e29-cf7a-4660-a52-30814d7a

If your not using a loadbalancer then you can do some slight modifications and roll thru this URL instead: http://YOURWOWZASERVER:8086/connectioncounts

Which gives detail about your specific server.

Right now i’m trying to figure out why I can’t do basic auth tho… the first example mentioned turning off authentication to make it work… which you have to do… but the ways I know of sending a un/pass for a file_get_contents isn’t working… annoying.

Also if someone doesn’t do it beforehand, i’m going to write up a quick script in a few in for making the connectioncount page look ‘pretty’.

–Chris