Okay, I couldn’t resist. Since I’ve been speaking so often on the wonders of HTTP Streaming in AJAX applications.

I posted recently about a technique to hold open such a connection using hidden IFRAMES and inline javascript tags.

Since a user agent executes javascript as it’s received, regardless of the rendering status of the rest of the page, one can create a server process that spits out inline javascript tags when a certain event happens on the server. The client interprets the javascript as soon as it appears and now you have a server process calling javascript functions! Kind of like the inverse of AJAX.

Combine that with some slick inter-process communication, and AJAX for client->server data, and you have a very low-latency client-server interaction.

Here’s the issue, if you’re using PHP, one must remember that PHP waits until a script is completed before it echos data to the client. Not very helpful in a streaming environment. Therefore, it is necessary to use a flush() call after every instance of echo that you want to be sent to the browser in real-time. You can configure PHP to behave this way all the time, but it’s seriously sub-optimal and should basically be used only for debugging.

So there you have it, client->server with AJAX, server->client with COMET, and server< ->server with traditional UNIX IPC.

It’s true, I actually follow a few races that don’t end on Sept. 5.

I have to admit, after a crushing 11 minute loss in the Alps, Floyd Landis delivered a stunning stage 17 and a top notch individual time trial. I watched all of stage 20 into Paris.

What a ride. With Basso and Ullrich out so early, it really was every rider’s race to lose. The last 20 miles are worth watching, even if you don’t follow cycling. So an American brings home the yellow jersey once again. It appears that all is right with the world.

Hotsoup

The new venture that Ron Fournier is putting together is a mix of social networking and policy discussion.

From the fact sheet:

Americans believe their institutions are failing them. Research and polls show a long decline in the public’s faith in government, business, and even organized religion. Opinion Drivers across the country are losing patience with party lines and PR spin.

They understand that the challenges America faces are complex and therefore require reasoning and intelligent discussion. They want smart debate, real answers, and most importantly, they want the opportunity to each be heard.

Opinion Drivers want access to the personalities who set the national agenda, and conversely, those leaders want direct access to the people who can help them shape public opinion.

Sounds like my kind of crazy! The site combines policymakers from both sides of the aisle with the public through a social networking paradigm. They have far exceeded my expectations with this and I’m looking forward to the release.

This morning’s Note opens with the following lede:

“We finally figured out why superscribe Ron Fournier left the Associated Press. We can’t say as much as we know, but we can say this: Fournier, who just got done writing a bipartisan book about the importance of community building in the Internet Age, has teamed up with political strategists from both sides of the fence and leaders from the Internet industry to create the next big thing in communications and community. It will all be clear to the world in the next 24 hours. Stay tuned.”

Ron Fournier is the author of Applebee’s America, a book about the Internet as a tool for Government-to-Citizen dialog.

Politics is notoriously behind the times with regard to technology, I’m anxious to see whether this is a real development, or more of the same.

AJAX applications are not sophisticated. They’re a special variety of kludge that we’ve been conditioned as computer enthusiasts to think are special. AJAX hinges on a technology which still isn’t always fully supported (XMLHttpRequest) and requires crafting sometimes overly complex XML documents to achieve simple data transfer. But it beats standard CGI in terms of responsiveness, so web developers follow the crowds of users to the land of no-refresh websites and drag-able maps.

However, even simple applications using these cool new technologies sometimes require a bit of unique thinking to keep them from drowning in their own complexity.

Case in point, the ever popular AJAX chat. It’s a common goal, and one which has given mixed results. For a single server implementation, the requirements are simple: a common exchange area for data, sometimes in the form of a database, and some method for synchronizing clients.

The problem with implementing this via AJAX is this: HTTP, which includes the XMLHttpRequest only goes one way. Applying Comet can help things along by providing an asynchronous server-event driven control flow, but polling for state change on the current data can still bring a powerful system to a crawl, especially if operations are disk-bound. Trust me on this, disk-bound read-write operations can really slow down your snappy application.

So how to effectively communicate state change and synchronize clients without clients polling the server for new data constantly?

Semaphores. I’ve been telling my roommates and family exactly how cool semaphores are. They stare at me strangely and move along.

Semaphores solve the problem by providing an incredibly quick method for synchronization. Each client attempts to spinlock a semaphore server-side. When the server receives new data, it releases the semaphore, which is then passed around among the waiting clients, informing them each that the new data is ready in shared memory.

There are variations involving MD5 hashing, sleeplocks, or more complex socket programming, but I find this method allows me to call an AJAX method from the server asynchronously, which can greatly improve the responsiveness of an application without overloading the client with a lot of unnecessary javascript.

SOAP, AJAX. You could almost guess what’s next. That’s right.

Comet.

HTTP Streaming.

AJAX makes it super easy to call server functions from the browser and have a callback received asynchronously, leading to very responsive, polished web applications.

Now Comet lets things go the other direction. Server to browser, through inline script tags in conjunction with AJAX.

Apparently Web 2.0 is all about cleaning things up.