Playing Nice with ShortStat

MT, TXP, or WP, whichever acronym you choose to use for your blogging needs you should be able to get it to work with ShortStat. (Except for Stan—but don’t worry, ShortStan 1.0 is almost ready for beta testing.) Since the most frequently asked question I recieve about ShortStat is, “I can’t get it to work with XYZ” (what is this, Jeopardy?) I thought I’d write a quick how-to.

First make sure that the obvious has been accounted for: your database config is set up properly, your include path is pointing to a file that actually exists and that ShortStat is turned on ($shortstat should be set to true in /shortstat/configuration.php).

MoveableType

No rules, just throw the ShortStat include anywhere. (Note: I’m not sure if this is true with MT PHP. Anyone have any experience with this?)

Textpattern

The ShortStat include must come after the textpattern(); function call in each of your section files. (Illuminated by Jon Hicks.)

WordPress

The ShortStat include must come after the wp-blog-header.php include. (Tip courtesy of Seth Thomas Rasmussen.)

Previous
Black ‘n Stan
Next
The Citroen C4
Author
Shaun Inman
Posted
November 15th, 2004 at 8:48 pm
Categories
Movable Type
PHP
ShortStat
Web
Comments
025 (Now closed)

025 Comments

001

The real question is when is the new version of shortstat going to be ready for public consumption?

Author
Ryan Brill
Posted
Nov 15th, 2004 5:09 pm
002

…And for the last time, it’s TXP, not TP! I’m using Textpattern right, not Toilet Paper. ;)

Author
Hans
Posted
Nov 15th, 2004 5:17 pm
003

Duly noted but allow me for the last time to say, it’s “ShortStat,” not “ShortStats” or “Short Stats.” It’s “short” because there’s no “s” at the end, get it? Good. ;)

(Not that anyone in this thread spelled it wrong but I’ve see it more than enough.)

Author
Shaun Inman
Posted
Nov 15th, 2004 5:24 pm
004

Oops sorry Ryan, didn’t mean to ignore your question. The way things are going, by the end of the year. I’m of a mind to under-promise and over-deliver though so don’t be surprised if it’s sooner.

Author
Shaun Inman
Posted
Nov 15th, 2004 5:28 pm
005

No problem, Shaun.

I’ve got the opposite problem (over promise, under deliver) going with my little project (TypeSpace). I was hoping to have it out the door around around a month and a half ago, and it’s still not ready to go. I’ve just got way too much going on right now (including a bunch of stuff that I had no idea was going to happen when I threw the mid Sept. ETA)… Hopefully I learned a lesson, though I’m not sure what it is. ;)

Author
Ryan Brill
Posted
Nov 15th, 2004 6:03 pm
006

Perfect timing for this post! Tonight, I am implementing ShortStat on my WordPress-powered site.

The one thing that I was going to request is that you post a full version of the latest Short Stat in the meantime so that people don’t have to install the older version and then find the update and run it. That exact problem is what has kept me from installing it until now. But I hear the software is just so damn good that I just have to have it.

Yeah, just thought I’d give some feedback.

Author
Stu Schaff
Posted
Nov 15th, 2004 6:47 pm
007

Hmm…

The ShortStat include is the very first item in my WordPress template, which means it comes before the wp-blog-header.php include, and I haven’t noticed any problems with ShortStat because of it.

What problems have been seen from having ShortStat included before the WordPress code?

Author
Ryan Berg
Posted
Nov 15th, 2004 6:57 pm
008

Shaun, does the inc.stats.php file still call die() when it cannot access the database? I personally find this quite unacceptable; why would you stop showing the contnets of the file, if the stats are not working?

I changed it to a simple if clause:

if($shortstat && SI_pconnect()) {
 ...
}

and that change requires that the database connection function returns true on success and false on failure.

I also put the include statement at the end of the pages, as then the user is already reading the page and wouldn’t care more about if the stats is taking somewhat longer.

Author
Janne Kalliola
Posted
Nov 16th, 2004 2:30 am
009

Janne, I’ve commented out the die() statements in v0.35b and handled things a bit differently in what will be the 1.0 release.

That’s a good point about putting the include at the end of the page but the time it takes to run ShortStat is really negligible (unless your server is excruciatingly slow). The next major version of ShortStat uses cookies and JavaScript to track some additional data that isn’t available to through PHP so it must be included before any data is sent to the browser (unless you decide to disable the new features).

Author
Shaun Inman
Posted
Nov 16th, 2004 3:40 am
010

This sucks, I am always on the back burner. I want my ShortStan.

Author
Jason Santa Maria
Posted
Nov 16th, 2004 4:03 am
011

Ryan Berg, The problem I had is that if the ShortStat include came before the wp-blog-header.php include, that page would not be listed individually in the Resources column of ShortStat. All the other stats appeared to work beautifully, and I still had number reflective of the total hits being displayed at the top of the Resources column, but nothing about how many times specific resources were getting accessed.

If you aren’t having this issue, then a) I feel sheepish, and b) I wonder what little detail was causing me grief… :

Author
Seth Thomas Rasmussen
Posted
Nov 16th, 2004 5:21 am
012

I wonder if someone knows how to get it working on IPB forums (Invision Power Board, version 1.2). The template admin modules don’t allow any direct php, so it’d have to go in a certain spot in a certain file.

Does anyone know what that spot is, or does someone have a better way?

Author
AkaXakA
Posted
Nov 16th, 2004 8:51 am
013

Seth,

My ShortStat doesn’t appear to be having that problem. You can take a look for yourself at My ShortStat Page.

Author
Ryan Berg
Posted
Nov 16th, 2004 5:43 pm
014

Akaxaka,

Simply put it somewhere in the PHP instead of the templates. I’m running ShortStat on one of my sites and have also installed it on a phpBB2 forum without any problems. I don’t know IPB’s PHP structure, but just drop the include line in the PHP that makes up the footer of every page.

Shaun, while the code works beautifully, I have one suggestion to make. My error logs keep getting PHP Notices from ShortStat. The same error keeps popping up, saying that variable X is undefined. A copy of my error log can be found here. This can easily be solved by using this syntax to retrieve variables: $var = (isset($_GET['var_name'])) ? $_GET['var_name'] : '';

It’s not a serious problem, but it does help you maintain good coding practices.

Author
Vincent Grouls
Posted
Nov 17th, 2004 3:48 am
015

Mr. Berg,

Would you mind posting(or emailing) part of one of your site templates that includes ShortStat as well as WordPress? I am curious to compare and contrast it with my setup so as to get to the bottom of this. I would not be surprised if my rearranging of the include calls was merely coincidental. I can share my template setup as well and perhaps we can both figure some things out…

Author
Seth Thomas Rasmussen
Posted
Nov 17th, 2004 5:27 am
016

Ryan and I spoke after he posted this, and we agreed on the following: As long as the ShortStat include is, well, included on every page, it doesn’t really matter where in index.php you call it (as long as it is run). It could be run before the wp-blog-header.php include, after the wp-blog-header.php, and I am pretty sure that you can even run it from within wp-blog-header.php! If the last option is true, I would say that it is probably the best option, as it keeps your index.php file nice and clean.

Author
Stu Schaff
Posted
Nov 17th, 2004 4:15 pm
017

Then my issue must be related to the script I run at the start of every page:

<?
// Check for UA acceptance of XML and serve as such, else serve as HTML
$mime="html"; //serve as HTML by default
// if the UA accepts application/xhtml+xml, serve as XML
if(stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")){$mime="xml";}
if($mime=="xml") //if we're serving as XML
{
    header("Content-Type: application/xhtml+xml"); //content type header
    echo "<?xml version="1.0" encoding="utf-8"?>n"; //xml processing instruction
}
else{header("Content-Type: text/html");} // else, we're serving as HTML
?>

Before the n in the line preceding //xml processing instruction is where the xml prolog goes, but it gets edited out by Shaun’s blog software.

Anyhoo, I know this for certain: The first three lines are 1) Include script above; 2) Include wp-blog-header.php; 3) Include ShortStat … and if I switch 2 and 3, that page will not record hits in the resources column. Everything else works as intended, I believe, though I don’t know if that file no longer registers hits in general either. I don’t know enough about ShortStat.

Similarly, I don’t know what would cause this conflict…

Author
Seth Thomas Rasmussen
Posted
Nov 17th, 2004 7:32 pm
018

Here you go, Seth. This is the very top of my index.php file.

<?php 
// ShortStat Function
@include_once($_SERVER["DOCUMENT_ROOT"]."/shortstat/inc.stats.php"); 
?>
<?php 
/* Don't remove this line. */
require('wordpress/wp-blog-header.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
Author
Ryan Berg
Posted
Nov 17th, 2004 8:30 pm
019

Well hrmm… like I say, I’m not sure what the deal is then. Perhaps something with declaring headers in my _init script, and then something that happens in the WP include ends up conflicting with ShortStat if it is included before WP??? I’m not terribly savvy with PHP, so if anybody can shed some light on this, I’ll send you hohos.*

*By hohos I mean no hohos at all.

Author
Seth Thomas Rasmussen
Posted
Nov 18th, 2004 6:38 am
020

Has anyone got this working with Expression Engine? I dropped the php include at the top of my index file and it doesn’t seem to be recording anything. Thanks for nay info.

Author
Justin
Posted
Nov 21st, 2004 7:31 pm
021

i am not sure why the link before isn’t working, anyways, this link works in case you need to look at the code (follow the “all blogs” link)

My Site

Author
Justin
Posted
Nov 21st, 2004 7:33 pm
022

[quote] The ShortStat include must come after the textpattern(); function call in each of your section files. [/quote]

Hmm, this doesn’t work for me. If I include the code before the textpattern(); function, then it works alright!

Author
Robin
Posted
Dec 2nd, 2004 9:58 pm
023

I tried to get ShortStat to run with MT PHP. No go so far. I’m getting an error message from the Smarty engine saying it can’t connect to the database through localhost. That’s the problem, my database isn’t located at localhost. The script works perfectly on regular PHP pages though (I’m running as PHP-CGI on Dreamhost). I only get an error in Dynamic PHP Movable Type pages.

Author
Mike Steinbaugh
Posted
Dec 10th, 2004 7:33 pm
024

Mike, I’m assuming you have the appropriate values set in configuration.php since it’s working elsewhere. I just did a little digging and mysql_pconnect() defaults to localhost if no server name is passed to it. Add this code to one of the pages and see if the $SI_db array is missing:

print_r($SI_db);

Shoot me an email, we’ll solve it off thread and then post the solution here.

Author
Shaun Inman
Posted
Dec 11th, 2004 3:49 am
025

Shaun, you absolutely rock.

Thanks for being so completely transparent and awesome. I’m learning so much from you.

Author
Jamie
Posted
Dec 15th, 2004 11:16 am