PHP Routing

If you’ve ever written web applications in Python using Pylons or TurboGears (>=1.1), you’re probably familiar with an incredibly handy tool known as Routes. It’s modeled after the Ruby on Rails routes system and does quite a marvelous job at mapping friendly, SEO URLs to useful code. If you’re not aware of it, you really should check it out.

However, I was curious to see if it were possible to create a Routes-inspired PHP library that would perform essentially the same task. I’m sure there’s an already-written PHP routes system, and I’ve allowed myself to fall into the not invented here trap. But, that’s part of the fun in coding: If you don’t like what someone else wrote or you want to give it a hand yourself, no one is stopping you. It’s great.

Thus, I’ve written Routing, the PHP routes system. It’s similar in syntax and intent to Python Routes with the exception that it’s PHPized (in other words: bastardized). If you read the sources, you might be able to see a little Python influence here and there (along with my frustrations toward PHP as a language vented in silence). I wouldn’t recommend it as anything short of entertainment as yet; I haven’t cleaned up the sources, and I expect they’re going to be really messy for a little while. The route search mechanism is awful, and I plan on refactoring it in a future revision. For now, the system works, and that’s good enough. (That’s my INTJ side talking.)

So, if you’re curious enough to take a look, head over to the Routing Trac page. I have some downloads posted there in a variety of formats (.zip, .tar.gz, and .tar.bz2). There’s no API documentation yet. I’m going to add it soon. Since Routing was born on Wednesday, August 5th, 2009 it’s quite young. However, I have some preliminary unit tests written (also incomplete) that you can read to get a general understanding of how Routing works. If you’re more interested in the principle behind Routing, you might want to read the documentation for Python Routes. Routes and Routing work roughly the same with the exception that Routing, unlike Python Routes, is extraordinarily buggy. I hope I can evolve this into something of an acceptable sibling to Routes but that will take time and a whole lot of effort. I have a few additional ideas, too.

1 comment.
***

NoSleep Released

So, I finally got around to writing a suitable replacement for the little Python script I was using to kill power management on my Thermaltake external USB/eSATA drive. But first, some history.

I didn’t mention it in the assembly guide I wrote for the Thermaltake enclosure, but as it turns out, the SATA chipset Thermaltake opted to use suffers from a rather annoying problem: If you leave it idle for more than about 15-20 minutes, it will turn the disk off. Since I like to have control over when the disk turns off, I had to write a script to periodically write a (blank) file to the disk. The idea being, of course, that if you can force some sort of activity, the drive will never go to sleep. (Edit: This isn’t entirely correct; based on information I received from Mike Fisher, it appears the source of the power down is actually the choice of hard disk–a Seagate ST3500410AS–that enters standby mode. I’ll update this accordingly once I find out if there is a means of stopping this.) As it turns out, this information isn’t completely correct either. If you’ve purchased one of these cases, it appears that the chipset will power the disk off only if it’s plugged in via USB. If you plug the bay in via eSATA, the disk will never shut off unless the OS commands it to.

The thing is, I had forgotten at least once or twice to browse to the root of my external enclosure where I kept the little Python script that did the trick. What’s more, it also required (under Windows anyway) a DOS prompt to exist as long as the application was running. Neither of these seemed to be suitable options.

Enter NoSleep

I decided to write NoSleep as a replacement for the little Python script that could. In fact, the replacement is even better–you don’t know it’s running. That’s the idea, anyway. Here are some highlights:

NoSleep…

  • Installs as a service. You don’t know it’s running in the background.
  • Isn’t invasive.
  • Scans for all removable media when you first turn the service on or install.
  • Monitors for new connected media.

This means that no matter what you do, be it unplugging an external disk and plugging it back in, NoSleep will keep an eye out. Whenever it spots something that could potentially go to sleep, it’ll start polling the disk. I use the same technique borrowed from the little Python script, too. Every once in a while, NoSleep will write to the contents of a file fittingly called .nosleep (the leading dot is intentional) and force the chipset on the drive to take note of activity, halting its sleep timer.

Why NoSleep?

Why? That’s a good question. Frankly, there are other applications out there that do the exact same thing. The thing is, all of the ones I found ran in the system tray and you had to add them to the startup folder (or the registry–though, at least one such application added itself automatically). I wanted something that would run without any indication it was running. I didn’t want a tray icon. I didn’t want to have to double-click an application every time I connect my poorly behaved enclosure. I just wanted it to work.

That’s reason enough.

So What’s the Catch?

There is none. NoSleep is free. In fact, I released it under the GPLv3. You can even browse the sources if you like. NoSleep does depend on my WMIDiskUtils library. I have released the latter under the LGPLv3, so you can use it in your own projects even if they’re closed source.

System Requirements

NoSleep does have some system requirements. First, it requires the .NET Framework version 3.5 or higher. While it should work on Windows 2000, I have only tested it in Windows XP SP3 and Windows 7. So long as you have .NET installed, I don’t imagine there would be much of a problem.

Take a look at the NoSleep Trac page if you need to file a bug report.

2 comments.
***

Python Gotchas: Class Attributes versus Instance Members

Links of the Week will be delayed until tomorrow or Friday.

Today, I’d like to share with you a real treat. It happened well into the evening last night when my coherent thought processes were lost in a semi-drunken stupor induced by lack of sleep (I don’t drink, but I do have slight insomnia sometimes). What was most ironic is that in the five or so years of writing in Python (off and on) I have never encountered this particular problem.

Click that fancy link (below) to read more. This is a fairly lengthy article, so make sure you have some free time! Read more…

No comments.
***