Death Race

Just came back from watching “Death Race” in the movies.  Back when I saw the trailer for this film, I thought to myself that it looks like a very safe recipe. I mean, you have Jason Statham as a driver, lots of cards, some hot girls, plenty of chases and shooting.  What are the chances of it going bad?  Practically none. But what are the chances of it turning into something interesting and original?

It turned out that whatever were the chances, they weren’t enough.  On one hand, we indeed have Jason Statham and lots of cars, shooting, and explosions.  The special effects were done nicely, and there was not much screen time without something brutal happening.  On the other hand, there is nothing new.  In fact, the story and the circumstances were simplified a lot, and in such a way that there is no need to explain anything or to connect the story pieces together with long talks or travels.  The plot is simple and uncovers itself in all obviousity (did I just come up with a new word?) at approximately the fifth minute of the movie.

Was it bad?  No, it wasn’t.  It was worth every penny, and was well worth the time I spent.  Chases were nice, characters were not bad, and I liked most of the effects.  The whole thing is pretty dynamic and enjoyable.  It was also made for the big screen.  But seeing it once is enough and I doubt that I’ll buy or rent it on DVD.  At least, any time soon.

An overall rating of 6 out of 10 is, I think, appropriate.

Righteous Kill

Either one of Robert De Niro and Al Pacino is enough to attract attention to the movie.  When they are both in the same movie – that’s something that needs to be seen, no matter what the critics or ratings say.  And that’s why I went to watch “Righteous Kill” today.

Altogether, the film was rather average – not much dynamics and action for a police movie, predictable story with a lot of cliches, dialogs really off sometimes, and so, and so forth.  But.  There was enough good acting, and there was enough thought provoking.  I mean it’s not a philosophical movie by any measure, but it covers a few morals and gives enough time to the audience to poke around the good, the evil, and the fine line between the two.

Overall, maybe not worthy the big screen, but good enough for a DVD rent.  6.5 out of 10.

Max Payne

I just came back from the movies – watched “Max Payne” with a friend of mine.  I wanted to see this film since I came across the trailer.  I know a few people who were waiting quite a bit for this film, since there is a video game with the same title, and, if I am not mistaken, everything started with a comics.  But don’t take my word for it.

The film turned out to be very pleasing visually.  Lots and lots of really cool special effects, focal points, perspective changes, and the like.  Lots of things are done properly – snow, water, fire, broken glass, flying bullets, explosions, and so on and so forth.  And all that comes together with nice soundtrack.  Pleasant experience.

As for the rest of it – the film was pretty weak.  The story is one of those usual stories that you have seen in a million other stories.  Characters aren’t very well developed though.  And the best characters never live up to their fame.  Nicely looking lady – killed in the beginning.  Really evil looking guy – even worse.  There is a lack of major battle, and whatever replaces it is a sorry excuse.  Disappointing.

Altogether, I’d give it a 6.5 out of 10.  If you like good visuals, then go see it on the big screen.  You won’t be disappointed no matter how lacking the rest of the film is.  But if you need more than just special effects, than wait for the DVD to come out.  That’s about all I can say about this one.

Oracle and PHP – the deadly mix

WI’ve spent most of the last week getting into, around, and out of the issues related to interoperability of Oracle and PHP.  Before you start laughing, cursing, and blaming, Oracle wasn’t my choice of the database for this specific project.  It’s just the company already had it installed and working for the background, and there needed to be some integration with the front, which is of course MySQL and PHP based.

First thing I do, obviously, is visit PHP.net to check for the prefix of the functions that I need for Oracle.  Through out my experience with PHP, that’s about the only thing I need to know to start working with the new database.  Oh, and the PHP module installed to provide those functions. Oracle interface for PHP is called is called OCI8.  All you need to do now is install the oci8 module.

Here comes the first trouble.  oci8 is not provided as a pre-compiled package for Fedora Linux.  There is an alternative yum repository – Remi, which has oci8 RPMs, but first of all, the oci8 module is compiled against somewhat outdated Oracle headers (version 10.2.0.4 instead of the latest 11.1.0.1), and it also needs to replace your native PHP and MySQL packages.  I tried that, and it sort of worked, but I wasn’t happy.  So I got my Fedora packages back and decided that I need to compile oci8 myself.

In order to compile oci8, one needs to download Oracle InstantClient (basic package) and some header files (devel package).  These can be downloaded from the Oracle web site, for free, minus the time for the registration.  The little trick here is that during oci8 compilation process, the includes are searched from locations which do not include the one from Oracle RPM.  I did a simple symlink of the includes folder to where Oracle headers were, and compilation went on just fine.  (Hint: otherwise you’ll get a whole lot of Zend related messages and a fatal error).  Gladly, I only had to do this path correction on the Fedora 9 machine.  My production server with Red Hat Enterprise Linux 5 compiled oci8 without any problems all by itself.

Update: more detailed instructions on the actual installation can be found here and here.

Now that oci8 installed and configured, I spent some time figuring the correct way to specify the DSN.   Oracle uses some weirdly name file (tnsnames.ora) in some weird location, but luckily there is a way to go around it.  More so, I recommend that you remove tnsnames.ora file altogether, since it can add to your troubles.  For example, if you mix spaces and tabs as whitespaces in that file, you are screwed.  So, just get rid of it.  The way you specify DSN is directly in the PHP script, and you use the syntax like so:  “//hostname.or.ip:port/dbname“.  Intuitive, I know.

Once you’ll get connected to the server, you have a whole bag of surprises waiting for you.  That is if you are too used to working with MySQL.  First is the syntax.  Oracle is using PL/SQL, so you wipe the dust of from that really old Pascal textbook that you have somewhere.  “begin :result := some.procedure.call(:param1, :param2); end;” – that sort of thing.  Secondly, you’ll be happy to know that prepared queries are supported.  So your workflow will slightly change.  Perl programmers will feel more at home here.  oci_bind_by_name() and oci_execute() are your friends here.  Oh, and while you are at, get familiar with the types of the parameters, because they are important.  And don’t forget that you’ll have to bind each and every variable in the query, or get a fatal error. And since you are learning something here, get ready for the oracle errors.  The most frequent one you’ll get would be something like “Failed to retreive the error message for ORA-12345”, where 12345 would be a number of the error.  So you’ll google for ORA-12345 and ORA-54321 and ORA-XYZZZ a lot.  But than you’ll have a wrapper library and you’ll be OK.

Update: as was noted in the comments, PL/SQL is just an option, not a requirement.  Also, most of the headaches of the above paragraph could be avoided by using one of the PHP frameworks.  I personally haven’t yet tried the framework yet, since I’d like to see things working directly first.  Especially since we are not in the test mode only.

The bigger surprise is still waiting for you though.  You are very likely to discover that OCI8 implementation for PHP is very slow.  And I do mean extremely very slow.  I couldn’t believe that it could be slow, so I went into the source code and OMG!  It is really slow.  The slow part is around fetch_all() against fetch_row().  Basically, it’s always row by row and never all, even if you tell it how many rows you need fetched.

In my case, I have the server a bit far away, and there is a possibility to get many rows back.  So even for a simple query with 140 rows in results I was getting 20 seconds execution time.  Oracle was serving results fast, the network was OK, machines on both sides were powerful and all, but it was still taking 20 seconds or more.

I am still trying to find the solution to this issue, but so far it seems that the current way I do it will be the way to do it.  And the way I do it now is the following.  Never ever run direct SQL queries.  Everything goes through a stored procedure.  The results are returned all in a single row.  And that single row has the BLOB (CLOB actually) with all results in one single XML.  Fetching works good enough to get it, and then parsing is done with one of the billion XML parsers for PHP.

In my case MiniXML worked pretty good until bigger results started coming in.  That’s when I learned an important lesson.  MiniXML parses XML with a regular expression.  PHP has a couple of settings in the configuration file that limits the size of the memory and recursion during regex parsing – pcre.backtrack_limit and pcre.recursion_limit.  If you really want to kill your server, set these to -1 (instead of default 100000) and try a regex against a 1 MB XML file.  Enjoy, cause it won’t be long before everything goes down. I didn’t feel like changing from MiniXML so we just implemented some limits in the queries and stored procedures on the Oracle side, and add a few checks in PHP fail rather than crash the system.

So, to some it up, here is my experience with Oracle and PHP from the last week:

  • I had to register on Oracle web site to download packages
  • I had to re-learn my long forgotten compilation skills
  • I had to go read some C
  • I had to step on the “re-inventing the wheel” path more than once
  • I am parsing XML when working with the database
  • I had a head ache more than twice
  • I didn’t have much fun
  • After all, it works.  Sort of.

One last point in this saga is about Googling.  Ask me any question, and I do mean any question, about MySQL.  Heck, even PostgreSQL.  And the answer is just there, on the first page of Google results.  In any human or programming language.  For any operating system.  You’ll be sorted out and working in less then a minute.   Then, try asking even the simplest of the simplest questions about Oracle and PHP.  Sometimes you’ll find something.  Some other times, you won’t.  The overall feeling I have is that not a lot of people are using Oracle with PHP, and those of them who do are in their majority not very happy.

Now I’ve joined the army.

Flickr on black

Being a huge fan of Flickr, I am always trying to bring more people to the service.  Because more people = more images and more comments, which, of course, means more fun and inspiration.

One of the most frequent reasons NOT to use Flickr that I’ve heard coming mostly from amateur and professional photographers was that Flickr is only available with white background and only with up to medium-sized images.  That is true.  While Flick is constantly improving their service, some features are still not there.  And maybe they are not coming any time soon.  But.  That doesn’t mean that there is no work around.  After all, the world of technology is blessed with plenty of excellent open source software these days.  So, here is how you can solve the problem of size and color, if you are one of those people who prefers it the other way around.

  1. Get yourself a copy of an real web browser – Firefox.
  2. Install Greasemonkey extension for Firefox.
  3. Install Flickr On Black user script for Greasemonkey.

Once you’ve done the above steps, go to Flickr and find a picture that you want to enjoy on black or in a different color.  On the image page, scroll down to the part where you can see “Additional information” on the right side.  Among them, you’ll see a few new links.  “View on black: Regular, Large” will be among them.

Click, and you are done.  The link will take you to another page, which will look something like this.  You can switch between Regular and Large size, as well as between black and white backgrounds right on that page.

P.S.: While you are getting Flickr on Black user script for Greasemonkey, look around.  There are thousands of other scripts to customize anything and everthing from Google search results and GMail to IMDB movie information and Twitter messeging.

P.P.S.: Alternatively, you can take a look at Flickr “Lights Out” or “Flickr in mostly black and orange” user scripts for Greasemonkey.

P.P.P.S: Many Greasemonkey scripts work perfectly in browsers other than Firefox – Opera, Safari, etc.  But I’d still recommend to use Firefox.