Fall Sale! Code FALL2024 takes 25% OFF our Pro Plugins & Books »
Web Dev + WordPress + Security

WP-ShortStat Slowing Down Root Index Pages

For over a year now, I have been using Markus Kämmerer’s (Happy Arts Blog) WP-ShortStat plugin for WordPress. The plugin is relatively well-maintained and remains one of my favorite admin tools. Great for popping in on stats without logging into Mint. Nonetheless, due to its IP/country-detection functionality, WP-ShortStat has experienced its share of difficulties (e.g., read through the change log on the plugin’s home page). In this article, I describe how WP-Shortstat slows down the root index-page of a site, and then suggest a (temporary) fix for the issue.

The Issue

I have heard of several different WP-ShortStat problems resulting from the country-lookup feature, including missing statistics, broken pages, and pages not loading (due to slowness of lookup server, etc.). Too many problems for something I really never look at anyway. The new (for me, anyway) issue with WP-ShortStat involves an extremely slow (or even non-loading) root index-page of any site running WordPress installed in a subdirectory. I experienced this problem under the following conditions at the exact same time and on three different blogs:

  1. WordPress installed in a subdirectory (not root)
  2. Running Markus Kämmerer’s WP-ShortStat plugin (version 1.7h)

The problem is that, all of sudden, and for no apparent reason (i.e., no changes had been made), the index.php files located in the root directory (i.e., outside of the WordPress installation directory) stopped loading. Well, okay, they would load, if you let them spin for long enough (average load time: ~3.33 minutes!), which is the same as not loading at all given the average visitor’s attention span. The bizarre thing is that every other page on the sites loaded normally (ha!). Indeed, all pages within the blog itself continued to load quick, fast, and in a hurry, but for some reason, the root index.php page would not. Here is a summary of the symptoms:

  1. Suddenly, site’s root index.php will not load (or loads very slowly)
  2. Meanwhile, all other site pages continue to load normally without issue

The Solution

Granted, most of my traffic is routed directly to internal pages (thankfully, only a fraction of total views are for the root page), so it is doubtful that many visitors noticed the problem before I could solve the issue. At first, I had NO idea why the root page — and ONLY the root page — would not load. Total stumper. Eventually, after a few rounds of the plugin-elimination game, the culprit was revealed! Disabling the WP-ShortStat plugin completely resolved the issue.

And that was just fine as a temporary fix, but I wanted to continue using the WP-ShortStat plugin — I just wasn’t ready to say goodbye (sniff). So, after some research1, trial and error, it became clear that the offending aspect of the plugin involved that incredibly uninteresting IP/country-lookup feature. Nice — I never used it anyway!

Thus, I decided to hack the plugin, solve the problem, and keep WP-ShortStat running tuf. Fortunately, the fix is a snap. Crack open the plugin file, scroll down to around line #21, and locate the following:

function determineCountry($ip) {
	
	$coinfo = @file('http://whois.happyarts.net/ip2country.php?ip='. $ip);
	
	$country = trim($coinfo[0]);
	
	if (
		$country == '(Private Address) (XX)'  || 
		$country == '(Unknown Country?) (XX)' || 
		$country == '' || !$country 
	) {
	
		return 'Indeterminable';
		
	}
	
	return $country;
	
}

Now, simply comment out the first two variable declarations, $coinfo and $country like so:

function determineCountry($ip) {
	
	// $coinfo = @file('http://whois.happyarts.net/ip2country.php?ip='. $ip);
	// $country = trim($coinfo[0]);
	
	if (
		$country == '(Private Address) (XX)'  || 
		$country == '(Unknown Country?) (XX)' || 
		$country == '' || !$country
	) {
		
		return 'Indeterminable';
		
	}
	
	return $country;
	
}

..and that should do it. Upload, test, and enjoy. If you were experiencing the issue described above — or any similar issue (pages not loading, slow server response, etc.) — this fix should definitely solve the problem. Sure, you won’t enjoy those nifty country IP lookup data, but you will eliminate all third-party server issues and other related problems.

If this hack worked for you, I would love to hear about it. Or, if you have encountered similar problems, or found a different solution to this or a related issue, please leave a comment and share your wisdom!

Footnotes

About the Author
Jeff Starr = Creative thinker. Passionate about free and open Web.
Digging Into WordPress: Take your WordPress skills to the next level.

4 responses to “WP-ShortStat Slowing Down Root Index Pages”

  1. Markus Kaemmerer 2007/07/25 12:07 am

    You should have updated to a newer version of WP-ShortStat. This had fixed the problem,too. The old version you are using (before 6. December 06) we used an HTTP based country detection service. This was slowing down our webserver to much. We switched of this service for months now (you can read it on http://blog.happyarts.de/wp-shortstat) and use UDP now. This is much faster for all users and our server can handle hundres of pings per second without problems.

  2. I was wondering if this would get your attention.. ;) Thanks for clarifying the issue, although I am still confused as to why the slowness only affects the root index in cases where WordPress is installed in a subdirectory. It seems that the problem would affect every page, unless another factor was involved. Either way it’s cool. I tested version 1.12a on another site and everything is running fine. Thanks for the great plugin by the way — it is definitely one of my favorites!

  3. First lookup maybe? Cached afterwards with teh object cache?

  4. Perishable 2007/07/30 6:22 pm

    Perhaps..
    How would that be checked/verified?
    I mean, just for fun..

Comments are closed for this post. Something to add? Let me know.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
Blackhole Pro: Trap bad bots in a virtual black hole.
Thoughts
I disabled AI in Google search results. It was making me lazy.
Went out walking today and soaked up some sunshine. It felt good.
I have an original box/packaging for 2010 iMac if anyone wants it free let me know.
Always ask AI to cite its sources. Also: “The Web” is not a valid answer.
All free plugins updated and ready for WP 6.6 dropping next week. Pro plugin updates in the works also complete :)
99% of video thumbnail/previews are pure cringe. Goofy faces = Clickbait.
RIP ICQ
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.