# Display current listeners using PHP

**URL:** https://community.wowza.com/t/display-current-listeners-using-php/34372
**Category:** Wowza Developer Dojo
**Tags:** wowza-streaming-server-java-api
**Created:** [March 3, 2010, 6:23pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372 "2010-03-03T18:23:20Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Dario\_Mindoro](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@Dario\_Mindoro](https://community.wowza.com/u/Dario_Mindoro)
#### Post date: [March 3, 2010, 6:23pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/1 "2010-03-03T18:23:20Z")

</div>

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]

---

<div class="post-metadata">

### Author: ![Chris\_Trainor](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@Chris\_Trainor](https://community.wowza.com/u/Chris_Trainor)
#### Post date: [March 3, 2010, 10:55pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/2 "2010-03-03T22:55:45Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Black\_Greek](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@Black\_Greek](https://community.wowza.com/u/Black_Greek)
#### Post date: [September 5, 2011, 7:59pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/3 "2011-09-05T19:59:33Z")

</div>

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]

---

<div class="post-metadata">

### Author: ![Charlie\_Good](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/charlie_good/32/383_2.png) [@Charlie\_Good](https://community.wowza.com/u/Charlie_Good)
#### Post date: [May 24, 2010, 3:20am UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/4 "2010-05-24T03:20:59Z")

</div>

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:

```auto
Authorization: Basic QWRtaW46Zm9vYmFy

```

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

Charlie

---

<div class="post-metadata">

### Author: ![Charlie\_Good](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/charlie_good/32/383_2.png) [@Charlie\_Good](https://community.wowza.com/u/Charlie_Good)
#### Post date: [December 2, 2010, 5:22am UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/5 "2010-12-02T05:22:49Z")

</div>

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

[https://www.wowza.com/tradeup.html](https://www.wowza.com/tradeup.html)

Charlie

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [May 23, 2010, 3:19pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/6 "2010-05-23T15:19:28Z")

</div>

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

Richard

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [May 24, 2010, 10:57am UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/7 "2010-05-24T10:57:06Z")

</div>

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

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

```

Change to:

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

```

Richard

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [July 5, 2010, 6:46pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/8 "2010-07-05T18:46:55Z")

</div>

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

[http://community.wowza.com/t/-/84](http://community.wowza.com/t/-/84)

Richard

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [July 29, 2011, 9:36am UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/9 "2011-07-29T09:36:36Z")

</div>

Try using double quotes on line 8:

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

```

Richard

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [July 29, 2011, 10:11am UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/10 "2011-07-29T10:11:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [September 6, 2011, 9:55am UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/11 "2011-09-06T09:55:40Z")

</div>

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](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](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](http://wowza.com/ide.html)

Richard

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [October 24, 2011, 10:37pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/12 "2011-10-24T22:37:33Z")

</div>

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

Richard

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [October 25, 2011, 6:07pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/13 "2011-10-25T18:07:08Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [October 25, 2011, 8:49pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/14 "2011-10-25T20:49:33Z")

</div>

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

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

```

Then restart Wowza.

Richard

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [September 11, 2012, 7:13pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/15 "2012-09-11T19:13:55Z")

</div>

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](https://www.wowza.com/docs/how-to-monitor-server-connections-load-and-application-statistics)

Richard

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [September 11, 2012, 7:15pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/16 "2012-09-11T19:15:40Z")

</div>

The 2nd link I meant to be this

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

---

<div class="post-metadata">

### Author: ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)
#### Post date: [March 13, 2013, 9:56pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/17 "2013-03-13T21:56:07Z")

</div>

Cool. Thanks.

Richard

---

<div class="post-metadata">

### Author: ![Alejandro\_Ferrari](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@Alejandro\_Ferrari](https://community.wowza.com/u/Alejandro_Ferrari)
#### Post date: [July 4, 2010, 9:53pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/18 "2010-07-04T21:53:29Z")

</div>

Xiaoqing Li,

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

You are using PHP?

Thanks,

Alejandro

---

<div class="post-metadata">

### Author: ![Alejandro\_Ferrari](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@Alejandro\_Ferrari](https://community.wowza.com/u/Alejandro_Ferrari)
#### Post date: [June 12, 2011, 11:54pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/19 "2011-06-12T23:54:11Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Chris\_Trainor](https://avatars.discourse-cdn.com/v4/letter/c/b487fb/32.png) [@Chris\_Trainor](https://community.wowza.com/u/Chris_Trainor)
#### Post date: [March 3, 2010, 11:44pm UTC](https://community.wowza.com/t/display-current-listeners-using-php/34372/20 "2010-03-03T23:44:43Z")

</div>

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](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](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

[Next page](https://community.wowza.com/t/display-current-listeners-using-php/34372.md?page=2)
