StreamCode Studio Get SHOUTcast Listener Statistics Using PHP | StreamCode Studio
Tutorials

Get SHOUTcast Listener Statistics Using PHP

SHOUTcast provides a statistics endpoint that allows your website to retrieve live information directly from your radio server.

Get SHOUTcast Listener Statistics Using PHP
16 July 2026 1 min read 111 views 0 comments
You can retrieve the current listener count and now-playing information from a SHOUTcast 2 server using its JSON statistics page.

Your SHOUTcast statistics URL normally looks like this:

http://your-server.com:8000/stats?sid=1&json=1


Replace the hostname, port and stream ID with your own server details.

PHP
<?php
declare(strict_types=1);
$statsUrl = 'http://your-server.com:8000/stats?sid=1&json=1';
$curl = curl_init($statsUrl);
curl_setopt_array($curl, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CONNECTTIMEOUT => 5,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_USERAGENT => 'StreamCode Studio',
]);
$response = curl_exec($curl);
curl_close($curl);
$stats = is_string($response)
    ? json_decode($response, true)
    : null;
?>


You can then display the current listener count:

PHP
<?php if (is_array($stats)): ?>
<p>
    Current listeners:
    <strong>
        <?= number_format(
            (int)($stats['currentlisteners'] ?? 0)
        ); ?>
    </strong>
</p>
<?php else: ?>
<p>
    Listener statistics are currently unavailable.
</p>
<?php endif; ?>


Display the Current Song

PHP
<?php if (is_array($stats)): ?>
<p>
    Now playing:
    <strong>
        <?= htmlspecialchars(
            (string)($stats['songtitle'] ?? 'Unknown'),
            ENT_QUOTES | ENT_SUBSTITUTE,
            'UTF-8'
        ); ?>
    </strong>
</p>
<?php endif; ?>


Complete Example

PHP
<?php
declare(strict_types=1);
$statsUrl = 'http://your-server.com:8000/stats?sid=1&json=1';
$curl = curl_init($statsUrl);
curl_setopt_array($curl, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CONNECTTIMEOUT => 5,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_USERAGENT => 'StreamCode Studio',
]);
$response = curl_exec($curl);
curl_close($curl);
$stats = is_string($response)
    ? json_decode($response, true)
    : null;
$listeners = (int)($stats['currentlisteners'] ?? 0);
$currentSong = (string)($stats['songtitle'] ?? 'Unknown');
?>
<?php if (is_array($stats)): ?>
<div class="shoutcast-stats">
    <p>
        <strong>
            <?= number_format($listeners); ?>
        </strong>
        <?= $listeners === 1
            ? 'listener'
            : 'listeners'; ?>
    </p>
    <p>
        Now playing:
        <strong>
            <?= htmlspecialchars(
                $currentSong,
                ENT_QUOTES | ENT_SUBSTITUTE,
                'UTF-8'
            ); ?>
        </strong>
    </p>
</div>
<?php else: ?>
<p>
    Stream statistics are currently unavailable.
</p>
<?php endif; ?>


Change the following line to your own SHOUTcast statistics URL:

PHP
$statsUrl = 'http://your-server.com:8000/stats?sid=1&json=1';


SHOUTcast 2 normally uses `sid=1`, although stations with multiple streams may use a different stream ID.

Article discussion

Share your thoughts about this article.

0

No comments yet. Be the first to join the discussion.

We've sent a download link to your email {}
Please check your inbox (and spam folder just in case).
The link will be valid for 24 hours.


Bell Online / MixStream


BellOnline offers fast, reliable UK hosting with strong security and excellent uptime - perfect for modern radio and web projects.

MixStream provides broadcast-grade streaming with crystal-clear audio and rock-solid stability, ideal for both hobby and professional stations.


Goto BellOnline Now!

Close