Optimus Wookie

Just a little corner for me to express my thoughts, code and ideas

What is PHP?

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 web pages. Since it’s a preprocessor, it runs on the remote web server and processes the web pages before they are sent to the browser. This makes it a server-side scripting language. The fact that it runs on the server has several benefits, and some drawbacks.

PROS
•    On the server you can have access to things like a database. This means that you can make a script that sort through large amounts of data, without the client having to download the whole thing.
•    It’s only the output from the script that is sent to the client, not the script itself. That means that you can make the script invisible from the end-user. That makes PHP-scripts browser-neutral; they don’t depend on some capability of the browser. It also means that you don’t have to worry that someone else can steal your carefully crafted script. It’s not like when you make a JavaScript everybody read the source of the webpage and your code. It has to be this way with client-side scripting, or else the client would be unable to get the source of the script, and therefore unable to do any scripting.
•    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.

CONS
•    By executing everything on the server, you put a lot of 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 look in to getting a faster 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.
You could of course still put some JavaScript in your pages. This is a very powerful combination between server- and client-side scripting. You could use PHP to fetch some values from a database, and then setup your variables in the JavaScript with these values.
In my opinion the benefits clearly outweigh the drawbacks and that is the reason why I’m using PHP and it is a fun language as well.

PHP NOTES
PHP is actually a rather uncomplicated language, despite its great powers. It’s a young language compared to other programming languages which is good because they put into it what the strengths of other languages. In fact much of the syntax is borrowed from C. This is noticeable 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, it made PHP an easy language to pick up. Even if you really don’t have any previous experience with C you should be able to learn it rather quickly.
Another thing that makes PHP easy to learn is it is relaxed way of dealing with the data types. It is very simple because you really don’t have to think of the types of variables at all. For example, if you assign a number or text 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, automatically. Heck you don’t even declare your variables. You just assign values to them, and then they are ready. If you are an experienced programmer you might say it’s not possible! My response would be, it just doesn’t matter and most of the time you’re interested in the value of the variable, and not the type. However if you really want, then you can indeed find out what type a variable is. This 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 web servers, checking mail via POP3 or IMAP, or URL encoding strings to protect special characters.

 
Add to Technorati Favorites


Computers blogs
eXTReMe Tracker