PHP stands for “PHP: Hypertext Pre-processor”. The funny abbreviation follows the style set by Richard Stallmann when he founded GNU: GNU’s not Unix! As the name says, it’s a pre-processor for hypertext, which is just another word for what most people call webpages. Since it’s a preprocessor, it runs on the remote web server and processes the webpages before they are sent to the browser. This makes it a so-called server-side scripting language. The fact that it runs on the server has several benefits, and some drawbacks. Let’s take the benefits first:
On the server you can have access to things like a database. This means that you can make a script that sorts through large amounts of data, without the client having to download them first.
You can make your own programs for use in your scripts. You could implement part of the script in C, and then call the program from your script to make it run faster. PHP is a parsed language, meaning that there are no compiled binaries. Every time someone requests a page with PHP-code, the parser looks through the page and executes any PHP-statements it might find. Fortunately this is a very fast process, but you might want to speed things up if you have a very complicated script.
When you make a C-program, you compile the source and then run the resulting binary. This makes PHP slower than an equivalent C-program.
As I said, there are also some drawbacks:
By executing everything on the server, you put more strain on it. With many concurrent requests, and large complex scripts, the server might not be able to handle it. But this isn’t a real concern because the parser in PHP is so quick. And if your server still can’t cope with the number of visitors, then you should be able to generate some revenue from banners on your site, and then pay for a bigger server :-)
The pages can’t do anything themselves — you need the server to do the magic. This means that the pages will lose some of their functionality if your visitors decide to save them to their computer.
In my opinion the benefits clearly outweigh the drawbacks — that’s the reason I’m using PHP :-). And I’m not the only one — an increasing number of websites are using PHP.
Some Background Information
PHP is actually a rather simple language, despite its great powers. It’s a young language, so the developers have had the chance to learn from previous language’s mistakes and implement their strengths. Much of the syntax is borrowed from C. This is reflected in the different conditional statements, the loop-structures, the boolean operators, and the assignment of variables. Since C is probably the most common programming language today, this should make PHP easy to pick up. Even if you don’t have any previous experience with C you should be able to learn it quickly.
Another thing that makes PHP easy to learn is it’s relaxed way of dealing with the types of variables. Its very simple: you don’t have to think of the types of variables at all! If you assign a number to a variable, then it just works. When you later try to output the variable to the browser it also just works. PHP takes care of converting the variable from an integer-type to a string-type, on the fly and automatically. To make matters even simpler, you don’t even declare your variables — you just assign a value to them, and then they are ready. If you are an experienced programmer (and especially if you normally program in strongly-typed language such as Pascal) you might say: “This can’t be real! There’s no syntax in this language. When you just declare variables like that you don’t have any control — you don’t even know what type a variable is!” All I can say to this is: It really doesn’t matter — most of the time you’re interested in the value of the variable, not its type. And if you really want, then you can indeed find out what type a given variable is. It could come in handy if you want to check to see if a parameter to a function really is of a given type.
Because PHP is meant to be used with webpages it has a lot of functions to deal with text so that you can get your work done quickly and efficiently. Because of that most of the built-in functions are simple and straightforward to use.
Being web-oriented, PHP also contains all the functions you’ll need to do things on the Internet. There are functions for connecting to remote webservers, checking mail via POP3 or IMAP, or url encoding strings to protect special characters.
Together with a good manual, you have all the help you’ll need. And if you get stuck — then you can count on the community. There has been a lot written about PHP on the net (you are reading just such a thing now :-) and there’s countless mailings-lists you can subscribe to.
Please refer to the installation instructions given in the PHP manual.
Now you have hopefully installed PHP, and you’ve been told about how easy it is, and how many things you can do with it. Let’s see it in action then!