Overflow in Wp-Dstats2 Wordpress plugin? 13422386 1019544571447648 7687716130941590224 o1

Overflow in Wp-Dstats2 WordPress plugin?

There seems to be a problem in the PHP code of the Wp-Dstats2 statistics plug-in for WordPress. The problem occurs when your number of unique visitors (unique IPs) grows large, typically somewhat less that 30.000.

The problem seems to be caused by the fact that the query responsible for the uniques is as follows:

select count(page) as count from wp_dstats2 group by IP;

after which the number of entries in the resultset are counted in PHP. Somehow this does not work when the resultset grows too large.

We can circumvent this nuisance by letting the query find out the exact number we are looking for:

select count(distinct ip) as count from wp_dstats2;

Instead of using the wpdb->get_results() we use the wpdb->get_var(), which leaves us with the following simplified dstats2_unique_reads() function:

function dstats2_unique_reads($range = 'all') {
    global $wpdb, $dstatstable;
    $qstring = "SELECT count(distinct ip) as count FROM $dstatstable";
    if ($range <> 'all') {
        $qstring = $qstring . " where " . dstats2_get_range($range);

    $uniques = $wpdb->get_var($qstring);

    echo $uniques;


  1. jon kvanvig August 20, 2005
  2. jon kvanvig April 4, 2005