PHP5 – a whole new ball park.

As you may have read in my previous post, I’ve installed PHP5 on my laptop. It’s running windows, but don’t hold that against it - it’s still running Apache as the httpd. I’ve heard some good things and some bad things about the latest incarnation of the PHP scripting language - most of the bad things are the fact that they’ve changed the language so much that many people are going to have to entirely re-write their applications. This is a problem, but hopefully only a relatively short-term one - except for the fact that it’s still VERY hard to find any hosting companies that supply servers with PHP5 installed and usable, since most people are still looking for good old PHP4 servers.

I’ve been playing with it over the last two nights, and from the things that I’ve seen, I’m blown away! I love PHP - most of my programming is for websites, and it lets you get most jobs done really quickly with a minimum of fuss. With the latest version, I can only see good things. The language has been re-written to be more suited to object-oriented programming styles, which is great for the larger application developers, and for the people that don’t use those sorts of things, the language doesn’t pick on you.

The inclusion of the simpleXML lib functions are a great boon to anyone using XML. I still can’t work out how to use the original built in PHP4 functions - I’m sure they make sense to someone. The new functions allow you to go (for example):

$parsed = simplexml_load_file( "test.xml" );

And it will load the file, parse it, and set $parsed to an object including all the data in the XML file. It means that you can access the data straight away, and don’t have to write a whole XML parsing library before you get down to the job of actually doing something useful with the data. I’ve been told that there are a variety of classes and libraries that have already been written, but they are all .php files, needing runtime processing by the PHP engine, and adding overhead to your application. The inclusion of built-in functions means they are written in C code, making them a lot faster and removing another step from the testing process (hopefully there’s no actual bugs in the functions!) 🙂

What I’ve been playing with tonight is the SQLite functions, which allow you to run a small (hence the name) SQL server based on files in the directory structure on your server. There’s a little bit of overhead in this of course, but for people running small sites that don’t need the full-blown power of MySQL or any of the other RDBMS’ it makes for a great addition to the language.

SQLite isn’t a separate daemon that you have to run, it’s built into PHP - meaning that if it’s part of PHP when it’s compiled, that’s all you have to do. The functions have been written just as the old mysql functions were sqlite_connect(), sqlite_query() and so forth. Obviously you have to know how to manipulate the data with SQL commands, but for anyone that’s done it before, it’s rather easy. Otherwise, there’s lots of tutorials on-line on how to set up a new table and so forth.

For anyone actually running a large site, using SQLite would be a disadvantage of course - it’s not designed for large amounts of users or large applications. Each time you load a page, it’s loading the database files afresh - being based on file system storage - rather than a proper RDBMS which can load databases into memory and allow for large amounts of users and concurrent requests. I think I might get around to writing something like phpMyAdmin for SQLite it could be a nice little project to play with, since there’s going to be a need for it by the community in the future. I guess I should probably check if someone else has already started a project like it, since I’ll probably be reinventing the wheel 🙂

#Programming #Work