PHP Session Thoughts

This is terse, because I am Angry, because Firefox crashed. Angry angry.

PHP Sessions lock. only one page (or resource) will load at a time. Especially visible if you load up several iframes or frames or something and they are session’ed. Also will be very nuisancesome with AJAX and XMLHttpRequest – while page is loading or XMLHttpRequest is running, no other content will load.

Solution 1 is to say session_write_close() after you’ve finished writing to the session. This is okay, but there’s still some lock contention before you say session_write_close().

My solution was to write a custom Session handler that doesn’t lock. It only locks when the session is being written (don’t want to have two processes writing to the session file at the same time, that’s just a recipe for complete disaster). It’s a little dangerous – if you store important data in the session, it could get mangled. But if you mostly read from your sessions, and don’t write to it too often, and don’t care if your writes to the sessions get stomped, you can try my method.

I put it on PHP.net, but in case it should ever disappear, here’s what I did:

1) Steal the example from session_set_save_handler().

2) Modify the write() method to do an flock() on the file before it writes to it, and unlock the file after the write is finished.

3) Add a proper Garbage Collection routine.

And our testing has shown that now you can get multiple concurrent loads running. Be very very careful though – the lock-free nature of this means you could scribble all over yourself. Don’t say you haven’t been warned. We haven’t blown anything up yet, but QA is doing their damnedest to.

DS vs. PSP

So two big handheld consoles Out In the Wild are the Sony PSP and the Nintendo DS. In Japan, the DS has outsold the PSP 80 gajillion to one. But in the States, they’re more even. The question is, which is better? And the answer is hard.

Graphics – No contest. The PSP completely smokes the DS. It’s not even close. It’s like looking at a child’s toy versus a graphics workstation. However (on the PSP), on some games, if you hold the screen at too much of an angle, suddenly you can’t see anything at all. This is because of the stupid shiny finish they put on the thing.

Ergonomics – The DS is uncomfortable to hold, it’s top-heavy, and using the stylus tends to make you inadvertently press the buttons. The PSP, on the other hand, is comfortable in your hands, works well in subway cars and is overall, just better.

Controls – The PSP’s analog controller is a waste of space. You might as well stick with the D-controller, because you can’t get any precision or control on that analog stick. It’s garbage. The DS, when playing an FPS game like Metroid, has the best controls next to mouse-and-keyboard I have ever used. An example – in Metroid, my character walks into a room – there are 4 or 5 hovering enemies, each above my vision line, not horizontally lined up. In 2 or 3 bursts, I’ve levelled them all. It’s right up there with mouse-and-keyboard, really. And I’m an old-school mouse-and-keyboard guy from the days of playing Marathon on my Quadra 630. And I’m not bad 🙂

Gameyness – The second you flip up the DS, it’s ready. You’re right in your pause screen, or wherever, and ready to get back into gear. With the PSP, the loading times are ridiculous. It makes me sweat more when I play the PSP – the fear of dying is not that I will fail, but that I will have to tolerate 2 or more loading screens before I can get back to try again. Conversely, if I die in Metroid, I’m already mid-try before the PSP would’ve finished even its first screen.

Durability – I think the DS wins here. No moving parts. Games are on memory card things.

Age – I should note that the games for the PSP tend to be more ‘M’ rated style games, and the DS tends to be more kid-friendly, but there is Resident Evil for DS, and there are cutesy games for the PSP, so I don’t imagine the line will always be so clear cut.

Looks – The DS looks like Doodoo. The PSP is shiny and sexy.

Cost – DS: $130, PSP: $250 (EDIT: I’m told it’s now $200). DS Games are $35 or less. PSP Games seem to be more, closer to $50 (or less). I think Nintendo has underpriced the market here – people are probably willing to spend more than $130 for a portable console, don’t you think? Maybe. Anyways, another interesting thing – Nintendo may very well be making money on each console sold – and _that’s_ very impressive, if that’s the case. Sony and even Microsoft can bleed out as much money as they want, selling consoles (portable and otherwise) at a loss, but good ole’ Nintendo is actually making dough, I bet.

The DS Lite coming out soon may be Nintendo’s answer to my ergonomics problems, and the fact that it looks like shit. If Sony’s next PSP simply has a Gig or 2 of cache-flash, or cache-RAM, then that could fix a lot of the problems I have with the PSP, too. So it’s definitely very close. But I have to say – the controls on the DS, at least for FPS gaming, are better than the controls on _consoles_. Really.

And an Addendum to my previous post, about Joel On Software – I think I see the difference between you and I, Joel. When your developers need a Subversion server, you install a multi-ton air conditioning unit. Whereas I would just get a small enough server that it wouldn’t need one. You integrate a Bayesian spam filter into your Bug-tracking system, but I would just make you put in a username/password, or one of those “type in this mangled text!” things. I’m not saying I’m right – I bet your solutions are more complete – but I bet mine get 90% of your results with 10% of your effort.

Scattered sleepless thoughts

We had a server problem at work – not my Main Premier SuperDuper Redundant Awesome server, but my Shitty OS X Server cobbled-together software RAID server. And I got literally zero sleep. Until I went home at around noon to catch a few hours and come back and finish the job. These are my thoughts without any organization. If you don’t like it too bad.

#1) Jumpey-jumpey is actually a specific incidence of boolean death, which is teh real problem. Most games nowadays avoid it – for instance, in GTA, if you’re at full health, a sniper rifle shot will not kill you, it will just take you down to a sliver of health (the same with a Chainsaw hit). Boolean death is really only a sin in a game which has a continuous health system. However, a heavy-hurting thing (like the chainsaw or sniper rifle) PLUS a long level where it’s almost impossible to get through wihtout losing a sliver of health can result in you getting attritioned out

#A) HFS+ is not a file system. HFS+ is a Shit System. It’s a system for being Shit. If you think data is nice, and you like your data, you would be wise not to put it on an HFS+ Volume.

I) Cyrus is an imap/pop server that CORRUPTS its mail database when the server is full. Let me repeat that, because, well, it bears repeating. Cyrus corrupts its mail database when the server gets full. That such a thing actually exists in production, and it is the default mailserver (MDA?) on OS X is an abomination.

α) Mac OS X Server is not my favorite server platform. If I see another rainbow beachball I will kill someone. But Mac hardware rocks. Firewire is your friend. So nice.

0) Being good at what you do doesn’t mean Not Failing. Because if you don’t ever fail it means you aren’t really trying very hard. It means instead Failing Well. Not just giving up and saying ‘eh, fuck it.’ It means trying your best, and making sure that other people get what they need. I think it can be kinda Noble

∞) Subway Stories Volume infinity: So I was sitting othe train playing Backgammon on my ridiculously shitty and cheap (but very cheap on the minutes) phone. I win one, I lose one – and I realize that it really depends more on your die rolls than how well you play, because the end result is to try to move your pips….

HEPP! PRAISE GOD! Praisehimpraisehimpraisehim JESUS! JESUS IS LORD! JESUS…<breaks into song>Jesus is wonderful, god is blah blah…SEVENTH DAY!

Nearly scared the shit out of me, that lady.

Anyways, thank you for hearing my disconnected rant. I am on 4 hours sleep. So be nice. Due to the fantabulousity that is Firewire, the files on my busted server are being transferred as we speak to the Not Busted Server, and all shall be well soon enough.

Video Game Annoyances

Though they aren’t fatal.

  1. Learn-by-Dying – No matter how clever you are, no matter how good you are, no matter how careful – the only way you’re going to get past this one particular area is by going through the first time and getting killed by it, and then knowing that it’s there beforehand the next time you go through. Any pretense you had about being in control of your situation or surroundings is far, far gone. Sorry. Only one way to learn it.
  2. Luck Through it – Just keep doing it until your luck happens to turn for the better. Games that feature instant-saving and instant-load actually will run into their own player workaround for this – where they save every time they have a lucky run through an area, and either ‘load’ every time they have an unlucky run, or die and just reload at their last lucky spot. The end result of this, is that the player’s ‘arc’ of save points appears as if he’s made every lucky break that’s possible.
  3. Jumpey-Jumpey – A long, complicated series of platforms or crates or whatever to jump between. Any false jump is death and starts you back at the beginning. Whenever you find yourself in this situation, you are supposed to exclaim,
    “Jumpey-Jumpey!” in an exasperated voice. Some platforms completely live in this world. I tend to get infuriated with this.
  4. Attrition Death – A long board or level which isn’t particularly hard, anywhere. However, you have to executed it near flawlessly, because any mistake you make reduces your life by an ever so small amount, and by the time you’ve gotten to the end, you have no health to do whatever it is you need to do, or you get killed by a lame low-level boring creature. You have been ‘attritioned out’.
  5. Cruel and Unusual Punishment – Death and failure are an inevitable part of video gaming. Video Game Makers, please, don’t make it more painful than necessary. For example, In Grand Theft Auto: Liberty City Stories, if you die, you lose your weapons and a chunk of money, and your car. You have to go and buy more, which means you have to steal a car – preferably the one you like, I’m partial to one particular model which I try to use for everything – and then you have to go buy weapons. Then you have to go drive to the mission-launching point, which may make you drive somewhere else. All the while, you have several ‘loading’ segments that kick in. Brutal. If I die, I just load my save game, because I don’t want to fling my PSP across the subway car in anger.
  6. I can do that, but my character can’t – This can drive you completely insane. There’s a little tiny step, about 6 inches high. Your character cannot get over it. You have to go around. That’s really really obnoxious. Notice that the converse of this (my character can do this, but I can’t) is fine.
  7. My own AI is dumber than me – Every time someone tries to make a 3/4 perspective game, or an over-the-shoulder game, they have to do some kind of AI for targeting and shooting. And inevitably, you get in a situation where you want to shoot that guy over there who is right in front of me, but when you say ‘auto-target’, it inevitably tries to target some other guy. Maddening.
  8. Camera’d to death – You’re walking through a simple straight sidewalk, but the camera is managing to do some crazy flip or pan at the same time. So you actually have to carve out some kind of crazy parabola on your controller in order for your hapless player to walk a straight line. I’ve also seen this in a 2D platformer where your character would go _behind_ some scenery, and you would have to just ‘know’ where he was. And you can’t see the enemies. Craziness making.

Funny, so many of my video game problems are related to external-view 3D FPS-esque games. Perhaps that says something.

And there are probably more, but I can’t remember them right now. Maybe I’ll do an edit and put them in if I think of them.

Good Architecture and Standards versus Bad

I’ve evaluated many pieces of technology now. Tons. And I think there’s some consistent trends to the stuff that I like. And the ones I don’t like, as much. Here’s some, and why:

#1A) Good: HTTP. Fantastic standard. Simple, powerful, extensible (headers!). I think that the World Wide Web is as good as we know it because of HTTP (not HTML, which I think is neither good nor bad. It just ‘is’.)

#1B) Bad: WebDAV. Turns this good fantastic standard into a confusing mess. I *love* the idea of PROPFIND. It’s a really great idea. But not, I think, in this standard. Why couldn’t there just be a nice simple way of getting directory listings, along with locking, and maybe some very very very simple concepts of file ownership? Instead there’s all this crazy crap, and no thing for ‘and here’s how you can extend it!’ The end result – we still use every other available protocol (FTP, SMB, AFP, et al) for file transport. How lame. I had to *SNIFF* the wire to figure out all of the hidden pieces in the various reference specifications and client specifications. What a mess.

#2A) ‘Good’ is not really the word I will use for this, but ‘adequate’ is: POP3. Yes, it’s annoying, but you can build a POP3 client or server pretty easily, and the entire Internet ran on that architecture for a very long time. Now being augmented heavily by, and perhaps supplanted by, IMAP4, but I’ve written POP clients and IMAP clients and even if you do a subset – POP is just so much easier. If they had extended POP3 instead, they could’ve made a better IMAP…

#2B) Bad: IMAPv4. It’s for many (me too!) a necessary evil – but there’s so much latitude in the implementation, it’s ridiculous. “You can use any separator character you’d like! Dots? Sure! Slashes? Why not!” That just costs more code. Why not just say that it’s way X not Y and if you don’t like it, screw off. And UIDValidity – christ! If you’re writing an IMAP client, you think, ‘Hey, I almost got it! Almost done!’ and then you realize you don’t cover UIDValidity changes. FUCK. Why not just insist it never happen? And leave the implementation to the servers? Same reason as before – it says in the standard, “Some email servers may not have any storage to store UID values…” When my friend Bryan and I read that, we both at the same time said, in mock sympathy, “Awwwwwwwwwwww!” Were I writing that spec, I’d say, Fuck ’em! Figure something out! MD5 the headers or something, I don’t care, but the UID _DOESN’T_ change.

#3A) Good: DNS. Impressively powerful standard for turning names into addresses. Completely decentralized. When extended, it can be used as an IP database, in some places (DNS RBL’s, etc). All this so that you can say ‘www.yahoo.com’ and get a nice answer.

#3B) Bad: DNS. Multiple ugly flaws in the specification. I’m with DJB on this one. Why specify the whole secondary protocol? There were plenty of them at the time, it’s unnecessary. Why require 2 DNS servers for a 2nd level domain? That’s unnecessary specification. And why not force referrals down to the client, instead of making them be performed on the server? E.g. the Recursion mode – bad idea. CNAME’s – totally unnecessary, should be at the Server’s discression. The second-to-last one feels like hindsight to me, but I think the other objections are valid.

#4A) Good: Nothing. Well, maybe, /etc/passwd. It doesn’t do anything, but it never breaks. And when it does break, you can vi it (for me, I ‘joe’ it) or pico it and fix it. So nice. And for 99.9% of the world, definitely enough.

#4B) Bad: LDAP – Here’s another one where you can just do whatever the hell you want. Actually authenticating People is almost secondary to this massive behemoth (sp?). It again allows you to do just about anything. You can define a person with 4 assistants, each of whom has 2 subassistants, and that you have 4 postal addresses. But what attributes are required in order to actually authenticate people? Who cares! How do you attach to the Directory? Eh, you decide! But if you want to define a PenisSize attribute, yes, you can have that. How useful. This is sadly one of the times where MS can just sit down and define their own implementation and swing the standard their way, and it actually helps.

#5A) Good: IPv4, TCP/IP, UDP/IP, etc. Again, there’s a reason why the internet runs on it. IP is a dirt simple and ugly way of chucking packets from hither to yon, and TCP is a very elegant way to put some nicer controls on top of that so you can get your packets in an orderly fashion. Multiple routing protocols allows for nice evolution, survival of the fittest and all (note – no routing protocol specified in the standard!), and we have neat evolutionary extensions such as NAT (or PAT in Cisco parlance).

#5B) Bad: IPv6. The entire whole wide huge internet is built on IPv4, but we need a whole new protocol for the next generation. No migrations for us! Sigh. And how many bytes is an address now? That’s ridiculous. 40 bytes of header it looks like? I don’t like that. A TCP frame is probably 2 Megabytes once you’ve put it on this monstrousity. Feh.

#6) Good: SMTP. It has its faults, but SMTP is simple and clean and makes a lot of sense. You could easily do something better, having 20/20 hindsight, but it’s very good considering how old it is.

#7) Good: XML. Verbose, yes, misused often, yes, no binary support, yes, BUT, it’s a great way of representing arbitrarily complex data. Great for interchange – and that’s what it’s designed for. Tons of people use it for wrong things, and that’s stupid. But for being used for what it’s actually for, it fits the bill nicely. I even like extensions like Namespaces and such (though I have a few nits to pick with that one).

#8A) Good: REST. One URI, one resource. GET it, PUT it, DELETE it. POST to it if you need to.

#8B) Bad: SOAP. One URI, everything goes through that, look at the data to figure out what’s going on, represent all kinds of crazy crap in the data, way too much definition of what’s going on in there. Yuck.

#9) Adequate: Apache. It’s a decent webserver, performs pretty well, can do just about anything, but it’s big and bulky. But anything that’s faster is rarely worth the effort. So I give Apache an ‘adequate’.

#10) Good: PHP. As a language purist, PHP will make you want to vomit. But what I like about it is that it’s so blue-collar, working class, get-it-done language. Yes, there’s no namespace support, and no naming scheme, but you can get a hell of a lot done in a few lines of code, and if you’re not psycho, you’ll be able to read that code later on. And it runs fast. Security has been a historical concern for it, but they keep getting better and better with that – but let’s be honest, there have been several worms using PHP vulnerabilities. Yuck. But some of that might be the Popularity issue – it’s so popular, so write worms for it…

There are more – but they’re not interesting. Ethernet is good. Wifi is adequate (the WEP/WPA/whatever crap makes it not Good). Windows and Linux and Mac OS X are either adequate or inadequate depending on who you have administering them. There’s no more of ’em I can think of.

There, a sufficiently punditey-looking post. Enjoy.

Brady’s Hair

My friend Bryan particularly enjoys the fact that my hair tends to disobey all those who try to thwart it.

Behold, it’s awesome power!

And I’m not sure if I should say ‘Thanks!’ or ‘Fuck you, buddy!’ to Bryan – but I’ll stick with ‘Thanks’ for now, because it’s very, very funny. If we can find the picture nicknamed, ‘The Führer’, it will all be worth it.

Edit NB – ‘The Führer’ is actually called “Uhm” – Bryan was concerned that giving it such a name might cause controversy or something. Fair enough.

Zaurus and such

So a friend of mine (I would link to him, but his home page seems to just say ‘You shouldn’t be here,’ so I guess you shouldn’t) lent me (semi-permanent loan, really) an old Sharp Zaurus.

Having been a Palm guy for a while, I knew it was not going to be anywhere near as pleasant to use as a Palm. And, for the most part, it isn’t.

However, it’s really a great piece of hardware, and I enjoy it a lot. It’s a little teeny Linux box. I went and started customizing crap, and I have tried out several different ROMs and all kinds of stuff. Memo to anyone using one of these things: Openzaurus Opie – Hentges ROM – is very very nice. That on a 128MB SD Card is actually very pleasant. And the device is ridiculously easy to re-flash. Reinstalling things on my Treo took FOREVER – this thing is flashed and up 5 or 6 times before I would’ve flashed my Treo even once.

I’m still trying to get it all tweaked and configured and everything the way I want it (mind you, this is a daunting task – I’ve had this thing for weeks now and am still trying to get it the way I want it.) Once I do I will probably make sure to take a snapshot of the disk image. I think I found a bug in Hentges’ AltBoot boot loader thingee – if so I guess I should toss the guy a patch.

So I managed to get Ruby on there – so I can continue to mess around with that – and I’ve installed thttpd – which has CGI support – which is really all I need. I don’t need mod_ruby or any such weirdeosity for development purposes.

The big ugly scary thing that I want to try to get on there is Sleepycat’s XMLDB. It’s a thing that lets you just jam XML into a database and index it up and search it and find it and stuff. Which is interesting for some stuff I’ve been thinking about. Although I still feel like the Flying Dutchman – forever doomed to recreate the same piece of software over and over again.

My desire to find a Fun Project to occupy me shall occupy, perhaps, another Blog posting later on…

Windows XP trimming

I’m working on this anemic laptop running WinXP, and I decided to start shutting down services I don’t think I need. I can’t go and set them to be disabled, because I’m not the only one who uses this, but I did stop as many as I could. I could stop more, if I could disable stuff and reboot.

This is what I got it down to. Less than a screen of services (barely) at 800×600. I write it here partially because I’m proud, and partially because if I have to reboot I want a reference to look at to see what I can shut down.

Checklist of Anti-bloat doodads I need

framebuffer support on my linux workstation
turn off VGA console! Why not!
Let’s do GRUB for bootloader
Firefox with GTK libs
so that means GTK, GDK, Gobject, pango, glib, and apparently some gcc libs (I guess for linking?).

and apparently quite a few others – here’s the output of objdump -p :

./browser/app/firefox-bin: file format elf32-i386

Program Header:
PHDR off 0x00000034 vaddr 0x08048034 paddr 0x08048034 align 2**2
filesz 0x000000e0 memsz 0x000000e0 flags r-x
INTERP off 0x00000114 vaddr 0x08048114 paddr 0x08048114 align 2**0
filesz 0x00000013 memsz 0x00000013 flags r--
LOAD off 0x00000000 vaddr 0x08048000 paddr 0x08048000 align 2**12
filesz 0x00010b80 memsz 0x00010b80 flags r-x
LOAD off 0x00010b80 vaddr 0x08059b80 paddr 0x08059b80 align 2**12
filesz 0x00000bf0 memsz 0x0000108c flags rw-
DYNAMIC off 0x000112fc vaddr 0x0805a2fc paddr 0x0805a2fc align 2**2
filesz 0x00000170 memsz 0x00000170 flags rw-
NOTE off 0x00000128 vaddr 0x08048128 paddr 0x08048128 align 2**2
filesz 0x00000020 memsz 0x00000020 flags r--
STACK off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**2
filesz 0x00000000 memsz 0x00000000 flags rw-

Dynamic Section:
NEEDED libmozjs.so
NEEDED libxpcom.so
NEEDED libxpcom_core.so
NEEDED libplds4.so
NEEDED libplc4.so
NEEDED libnspr4.so
NEEDED libpthread.so.0
NEEDED libdl.so.2
NEEDED libgtk-x11-2.0.so.0
NEEDED libgdk-x11-2.0.so.0
NEEDED libatk-1.0.so.0
NEEDED libgdk_pixbuf-2.0.so.0
NEEDED libpangoxft-1.0.so.0
NEEDED libpangox-1.0.so.0
NEEDED libpango-1.0.so.0
NEEDED libgobject-2.0.so.0
NEEDED libgmodule-2.0.so.0
NEEDED libglib-2.0.so.0
NEEDED libm.so.6
NEEDED libstdc++.so.5
NEEDED libgcc_s.so.1
NEEDED libc.so.6
INIT 0x804b168
FINI 0x8057394
HASH 0x8048148
STRTAB 0x80493dc
SYMTAB 0x804877c
STRSZ 0x15a6
SYMENT 0x10
DEBUG 0x0
PLTGOT 0x805a484
PLTRELSZ 0x3a0
PLTREL 0x11
JMPREL 0x804adc8
REL 0x804abb0
RELSZ 0x218
RELENT 0x8
VERNEED 0x804ab10
VERNEEDNUM 0x3
VERSYM 0x804a982

Version References:
required from libstdc++.so.5:
0x081a2972 0x00 06 GLIBCPP_3.2
0x056bafd2 0x00 04 CXXABI_1.2
required from libpthread.so.0:
0x0d696910 0x00 03 GLIBC_2.0
required from libc.so.6:
0x0d696913 0x00 08 GLIBC_2.3
0x0d696911 0x00 07 GLIBC_2.1
0x09691f73 0x00 05 GLIBC_2.1.3
0x0d696910 0x00 02 GLIBC_2.0

Add to listbash, libc, sh, curl (?)

So I was thinking about how the whole doodad might work. And like I was saying – or I think I was – you’d have all the binaries and libs and everything owned by good ole Mr. Root. And I like the idea of getting rid of /sbin/init and replacing it with a shell script that maybe does like a webDAV mount of something from a central server, then launches firefox from in the middle of that. I like webDAV because of the webbiniess, but maybe it will have to be SMB or NFS or something. Anyways, you could do this with a small sh script. (Read in username, password, mount with said, if succesful, launch firefox?)

Eventually you could have something where it downloaded a sh script (if it’s available) and executes it, after doing a openssl signature check. (You wouldn’t want to download an sh script and then just run it, someone could do something nasty with DNS spoofing and make you do something terrible. Multiply by thousands of machines and…yuck).

In terms of making a teeny tiny eensy weensy leeenoox, I have looked into Linux From Scratch, and it sounds like that might be a direction I might go – or I could just burn a Knoppix CD and just use that as my ‘host’ system.