Category: Uncategorized

Hit Tracking with PHP and MySQL

Recently there was an outage at a hit-tracking vendor I was using to track the hits on my externally hosted blog, leaving me with a gap in my visitor data several hours long. While this was an inconvenience for me, I realized that this could be mission critical failure to an online business reliant on this data.
To resolve this, I used the PHP HTTP environment variables and the built-in function for converting IP addresses to IP numbers to create my own hit-tracker. It is a rudimentary tracking tool, but it provides me with the basic information I need to track visitors.
To begin, I wrote a simple PHP script to insert tracking data into a MySQL database. How do you do that? You use the gd features in PHP to draw an image, and insert the data into the database.


header ("Content-type: image/png");
include("dbconnect_logger.php");
$logtime = date("YmdHis");
$ipquery = sprintf("%u",ip2long($_SERVER['REMOTE_ADDR']));
        $query2 = "INSERT into logger.blog_log values \
               ($logtime,$ipquery,'$HTTP_USER_AGENT','$HTTP_REFERER')";
        mysql_query($query2) or die("Log Insert Failed");
mysql_close($link);
$im = @ImageCreate (1, 1)
or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate ($im, 224, 234, 234);
$text_color = ImageColorAllocate ($im, 233, 14, 91);
// imageline ($im,$x1,$y1,$x2,$y2,$text_color);
imageline ($im,0,0,1,2,$text_color);
imageline ($im,1,0,0,2,$text_color);
ImagePng ($im);
?>

Next, I created the database table.


DROP TABLE IF EXISTS `blog_log`;
CREATE TABLE `blog_log` (
  `date` timestamp NOT NULL default '0000-00-00 00:00:00',
  `ip_num` double NOT NULL default '0',
  `uagent` varchar(200) default NULL,
  `visited_page` varchar(200) NOT NULL default '',
  UNIQUE KEY `date` (`date`,`ip_num`,`visited_page`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

It’s done. I can now log any request I want using this embedded tracker.
Data should begin flowing to your database immediately. This sample snippet of code will allow you to pull data for a selected day and list each individual hit.


$query1 = "SELECT
                bl.ip_num,
                DATE_FORMAT(bl.date,'%d/%b/%Y %H:%i:%s') AS NEW_DATE,
                bl.uagent,
                bl.visited_page
        FROM blog_log bl
        WHERE
                DATE_FORMAT(bl.date,'%Y%m%d') ='$YMD'
		and uagent not REGEXP '(.*bot.*|.*crawl.*|.*spider.*|^-$|.*slurp.*|.*walker.*|.*lwp.*|.*teoma.*|.*aggregator.*|.*reader.*|.*libwww.*)'
        ORDER BY bl.date ASC";
print "<table border=\"1\">\n";
print "<tr><td>IP</td><td>DATE</td><td>USER-AGENT</td><td>PAGE VIEWED</td></tr>";
while ($row = mysql_fetch_array($result1)) {
        $visitor = long2ip($row[ip_num]);
        print "<tr><td>$visitor</td><td nowrap>$row[NEW_DATE]</td><td nowrap>$row[uagent]</td><td>";
	if ($row[visited_page] == ""){
    	    print " --- </td></tr>\n";
	} else {
    	    print "<a href=\"$row[visited_page]\" target=\_blank\">$row[visited_page]</a></td></tr>\n";
	}
}
mysql_close($link);

And that’s it. A few lines of code and you’re done. With a little tweaking, you can integrate the IP number data with a number of Geographic IP databases available for purchase to track by country and ISP, and using graphics applications for PHP, you can add graphs.
For my own purposes, this is an extension of the Geographic IP database I created a number of years ago. This application extracts IP address information from the five IP registrars, and inserts it into a database. Using the log data collected by the tracking bug above and the lookup capabilities of the Geographic IP database, I can quickly track which countries and ISP drive the most visitors to my site, and use this for general interest purposes, as well as the ability to isolate any malicious visitors to the site.

Browsers: The Window and The Firehose

Three years ago, in a post on this blog, I stated that I thought that the browser was becoming less important as more data moved into streams of data through RSS and aggregated feeds, as well as a raft of other consumer-oriented Web services.
This position was based on the assumption that the endpoint, in the form of installed applications, wouldcontinue to serve as the focus for user interactions, that these applications would be the points where data was accumulated and processed by users. This could be best described as the firehose: The end-user desktop would be at the end of a flood of data being pushed to it a never-ending flood.
Firefox and Chrome have changed all of that.
The browser has, instead, become the window through which we view and manipulate our data. It’s now ok, completely acceptable in fact, to use online applications as replacements for installed applications, stripping away a profit engine that has fed so many organizations over the years.
The endpoint has been shown to be the access point to our applications, to our data. Data is not brought and stored locally: It is stored remotely and manipulated like a marionette from afar.
While Chrome and Firefox are not perfect, they serve as powerful reminders of what the Web is, and why the browser exists. The Browser is not the end of a flod of incoming data, it is the window through which we see our online world.
While some complain that there is still an endless stream of data, we control and manipulate it. It doesn’t flood us.

Google Chrome: First Impressions

Google Chrome is out. And from first impressions, it is stinking fast. However, i do have some gripes.

  1. Comes with link underlining enabled. I hate this. It’s the first think I disable in Firefox and any browser that supports disabling underlining
  2. Where’s the “get your hands dirty under the hood” option list? I love the Firefox about:config list. Chrome needs this.
  3. Ads. I know. There is little chance for built in ad-blocking, but it’s on my wish-list.

Otherwise, it’s good…so far. And the memory usage is, well, definitely less intrusive.
I plan to use this for a while and see what happens. I will likely find something that drives me back to Firefox eventually.
Ok, found a weirdness when you use a <li> tag in the WordPress editor. It seems that it starts injecting <div> tags to differentiate paragraphs after you close out the list.

Web Performance: TechCrunch Goes Crunch

It’s the first day back after the last long weekend of the summer. There is a a great amount of news flooding the intertubes, and what happens?
TechCrunch has a small issue.

techcrunch-crunch-sep022008

It’s likely they’ll be back soon, but it’s still an interesting thing to see.

Update – 09:17 EDT (13:17 GMT)

TechCrunch is back up as of 08:49 EDT (12:49 GMT).

Google Chrome: See No Evil, Do No Evil – An Internet Performance Perspective

The intertubes of the Web are abuzz with talk of the new, open-source Google Chrome browser [two articles here and here]. I will not presume to wade into the debate of whether it is necessary, or what strategic business goals Google has set that rely on having its own browser. I will limit my comments to the area of Web performance.

Open-Source Browser: Ours or Theirs?

When I read that Google Chrome was an open-source browser, the first thought was: is it theirs or a re-branded Firefox? No one knows at this point, but that will have a direct effect on how the browser performs, and how extensible it will be.

HTTP Standards

Unlike other standards, HTTP standards set out how a browser uses the underlying TCP stack. MSIE6/7 have very broken implementations, and MSIE8 is building on those by increasing the number of connections per host to 6, up from 2 set out in RFC 2616.
Firefox can be configured to mangle this as well, but by default it plays by the standard, adding the option of HTTP pipelining into its mix of persistent HTTP connections.
It will be VERY interesting to see how Google Chrome comes configured out of the box, and how much control users have over the HTTP behaviour of this new browser.

(X)HTML/CSS/JS Standards

This area is a mess. No browser implements this standards in a way that is completely consistent with the written text, and page designers have to use a variety of page testing products (such as BrowserCam) prior to release to ensure that their design is somewhat presentable in all browsers on all platforms.
The rendering of Javascript will be crucial in this new browser, as so much of the new Web is built on applications that are almost completely Javascript-driven.
I am sure that there will be sites that will be completely mangled by the new browser, but, knowing Google, we will be getting a 2.0 release, the 1.0 release being used within Google for a while now to test it under real-world conditions.

Caching

As a few sites in the world do use cache-control headers properly, it will be interesting to see how a browser created by one of the major ad-serving and search providers on the Web tracks page objects. Will it follow explicit/implicit caching rules? Or will it impose a heavy penalty on bandwidth by downloading objects more frequently than other production browsers do?

Proxies, and the Debacle of the Google Web Accelerator

Back in 2005, Google launched a badly designed and gighly flawed product called the Google Web Accelerator. This product proxied Web traffic through the Google network and allowed the company to develop a pattern of user browsing habits and search selections that would allow them to better target their ad products.
I have a great fear that this will be an integrated part of the Google browser project. If it is, it should be a configurable option, not an out-of-the box standard.
I am sure that there will be a few performance conversations that occur around the Google Chrome browser in the weeks ahead. I look forward to hearing what the community has to say about this new addition to the browser wars.

Thoughts on the China Market

At the The China Vortex, Paul Denlinger discusses how there is no unified “China market”, no monolithic, simplistic, single-minded Goliath that the rest of the world is trying to deal with. While I do not have the depth of on the ground experience that Mr. Denlinger has (I have not yet been blessed with the opportunity to visit or do business in China), I can see the truth he brings to the discussion.
One of the great pits that Western culture falls into when dealing with the China problem is just that: It is seen as a problem, not an opportunity to expand and learn from a culture that deals with life, philosophy, and business in a very different manner.
This should come as no surprise to any astute student of History, or even modern geopolitics, as the way that nations deal with perceived threats or challenges is to create a national culture of The Other, the us-v-them foreign policy.
When Japan was the country du jour in the 1980s, the Western World respected it, in a very shallow way, as a fellow industrial nation with a strong warrior culture. However, it was treated in a simple way, with Western media portrayals that strengthened perceived stereotypes, and plastered over the profound differences that exist within Japan, and within the Japanese people.
China is even more of a victim of this Politics of the Other, having spent more than 50 years as one of the adversaries in the Cold War, being vilified and portrayed in the least flattering light possible. Even without the base Human interpretation of simplistic interpretations of the Other, the West is crippled from the start in its attempts to understand a nation as large, diverse, and fractured as China.
China is far more than Beijing, Shanghai, Hong Kong and small cadre of smaller, but no less important industrial / post-industrial metropolitan areas.
Drawing on my experience in trying to interpret Internet performance data from within this nation, it is clear to even the casual observer that the Chinese Internet does not simply exist in the major cities. It extends into the far reaches of the country, fractured by the internal conflicts of the connectivity providers, government officials at a many levels, and the unstoppable drive and creativity of the people who see the Internet as an opportunity to make their way in their world.
Cultural and national stereotypes are the way that humans ineffectively deal with the differences that exist. But just as the terms “All Brits..”, “All the French..”, “All Germans…”, “All Argentinians..”, et al. should be treated with disdain and seen as a sign of ignorance, using the words “All Chinese…” or “All of China…” should be quickly quashed and carted off to the dustbin of simplistic paranoia and xenophobia.
There is no such thing as a threat. As it is often stated in other contexts, a threat is simply an opportunity that is hidden by your own prejudices.

Streaming v. Torrent – The true promise of on-demand

Steve Gillmor comments on TechCrunch today that Comcast’s caps on bandwidth may finally drive people from the land of torrents, and to the land of streaming. [here]
While I agree that the promise of streaming is long overdue, there is the one area that streaming still can’t fill: The mobile viewer. I don’t mean folks on mobile phones, although with the growth of 3G in the Americas (Europe and Asia laugh at us in the area), the mobile market will become more important.
No, I am referring to the mobile, laptop-using traveller, mainly the business traveller, although leisure travellers are starting to take their laptops with them more often. Streaming doesn’t work on the road, in a hotel with a crappy connection, in an airport, or somewhere were the 3G isn’t 3G enough.
While streaming will become more prevalent, it won’t unseat the culture of Torrents for a few years yet. It will happen. But affordable, reliable connectivity saturation across the Americas has to occur first. And, in some ways, Comcast and the other providers are the ones hampering this process.
The focus of the connectivity providers on their dinosaur cage-match with the FCC has left them ignorant of the asteroid screaming toward them. In order to create a streaming market that they can profit from, they have to open the pipes, lower the costs, and increase the options for the consumer of their Internet/bandwidth services. If the connectivity they provide to the consumers can’t support the desire for the streaming economy, the Torrent reality will not fade away.

Streaming and the Beijing Olympics – Is it live? Or is it NBC?

Over at NewTeeVee, there is a detailed look at the way that the streams were served and who served them. They also have a great discussion of the P2P and Torrent downloads, serving as an alternate method of getting the high quality streams out to a larger audience.
But John Furrier poses an interesting question, just before he quotes the entire NewTeeVee post: What’s the largest audience for a live stream?
Most of the streams that were viewed by people at NBC and other media providers were delayed. And while the concept of streaming is still valid, it doesn’t fulfill the promise of an “as it happens” delivery of streaming media.
So folks, what is the largest live video stream audience?

Bylined Article up at StreamingMedia.com

My bylined article Industry Perspectives: Best Practices for Flawless Web Multimedia Streams is up! Go check it out!
The discussion centers around how to approach monitoring and measuring the performance of Streaming Media, an area that is far more challenging than traditional Web page and site performance measurement.
There are a number of challenges an organization faces when deciding to adopt some type of streaming media strategy. The main one is “Do we go it alone?”.
The article addresses a number of these areas.

Copyright © 2025 Performance Zen

Theme by Anders NorenUp ↑