April 28th, 2008

Weird PHP/Flash/Flex Problem

The last little while I’ve been writing a new MP3 player for Fuzz using Adobe’s Flex Framework.

OK - first off… before I discuss the problem I gotta say Flex is pretty awesome. I’ve tried Flash before and have always been confused by the whole thing. Timelines, drawing tools & all the other designer-oriented stuff just stumped me. I’m a programmer so getting my head around Flash was just not happening… I don’t think that way. But Flex is fucking cool. The prologue of O’Reilly’s Programming Flex 2 pretty much addressed all my frustration with Flash and explained why I’d like Flex… Well, they’re right. It’s just like writing an app. You get handlers, listeners and all that crap that programmers understand and there’s no timeline or Illustrator-style, insane pen tool. It reminds me a lot of Swing and other shit like that.

Anyways… ya, Flex is cool. But, let’s get to the problem…

Here’s the problem:

The MP3 player streams songs off Fuzz, obviously. Also, downloading a song is quicker than listening to it real time. So a song downloads in 20 seconds, but takes 3 minutes to play… makes sense right. OK but here’s what was going on:

If you hit “play” on the player the song starts downloading and once it has enough it’ll start streaming. But, if you click on a link before the DL finished the request for the new page would not register until then download was complete.

A different manifestation of the same issue comes up when you have 2 browser windows open. Window 1 is playing music while you use window 2 to cruise around the rest of the site. Again, same problem. If you clicked on a link in window two to navigate to a new page nothing would happen until window 1 finished downloading the current song.

Fucked up huh?

I started fucking with every imaginable header in the proxy which serves up the song. Nothing seemed to work. Keep-Alive etc… I tried everything. I started tweaking Apache settings to no avail. Totally had me stumped.

I finally figured it out; The solution was to close the PHP session in the proxy before the code started outputting the MP3’s contents. Why’s this fix things? No idea but it works and I’ll look into “why” tonight at home.

A partial fix was to ignore_user_abort. In the single window case this worked fine but not in the 2 window situation.

Anywho… If anyone’s streaming MP3’s via PHP and wonders why links don’t respond just close your PHP session before spitting out the binary. I’ll check into why this is an issue and update when I understand the technicals.

listening to Nothington and jonzing to play some music soon.

Search This Blog

Categories