Quick Technology Index

Share Button

First, can you give me a very quick summary of PHP?

PHP stands for Pretty Hair-brained Programming Footnote 1: Particularly Horrid Programming? OK - if you’re a project manager, you may be smiling at this point, but if you’re a PHP programmer, you’re far more likely to be really irritated. PHP is one of the most popular programming languages in the world, so we’re probably irritating a lot more people that we’re amusing. Hmmm... perhaps we should have paid the extra ten bucks to keep our contact information private when we registered our domain name. After all, there’s a lot of nut-job PHP programmers out there. Oh... I didn’t mean you though. You’re completely sane. . Not really, but that’s a little easier to remember than what it really stands for. “PHP” stands for “PHP Hypertext Preprocessor”. The first P in PHP stands for PHP, so the acronym is infinitely recursive and we already have a bug… on the very first letter. Actually, PHP’s problems have far more to do with how it is frequently used than with the technology itself, but we’ll get to that soon. Let’s first review what it is.

PHP is a wildly successful and very popular “server-side scripting language” that enables web servers (like Apache or Microsoft IIS) to do more than just serve out static text and images. PHP allows web pages to access a database or to perform complex calculations.

If you’re a small business and

  1. you are using an ISP to host a web page for you, and
  2. you need your web page to do more than display static text, and
  3. the ISP doesn’t already provide a service to perform your dynamic function for you (like take credit card payments)

then the chance that you’ll end up using PHP are extremely high. For example, ISPs (like Yahoo) frequently provide a service to take credit cards. You don’t have to write any code to do this since they’ve done it for you. But if ISPs did not provide such credit card-taking services, you would have had to write either a Perl or PHP application to do this (Yahoo supports Perl and PHP, but other ISPs support Ruby, Python, and Microsoft-based solutions). If you want to enhance your web site to allow people to sign up for a newsletter of some sort (we’ve considered doing that since many people suffer from insomnia), PHP would be a natural choice for that. PHP is a good choice if you need to interact with a database and you’re web page is hosted by an ISP.

So how will they "install" PHP in our existing web environment? Where does it go?

PHP is really a patch to HTTP Servers (like Apache or Microsoft IIS). Once that “patch” is applied, those web servers know when someone requests a web page that ends in “.php”, it should treat the request in a special manner. A PHP-enabled web server knows where to look for the PHP source code that corresponds with the requested URL, and it knows how to open and execute the instructions in the PHP source file. The web server (probably Apache or IIS) then uses the PHP source to dynamically construct the web page and return the resulting HTML to the end user’s browser. PHP enables the web server to execute logic (PHP looks a lot like Java or C++) since that can’t be done in HTML (see HTML web page). PHP can also interact with databases. You don’t want browsers directly accessing your database or executing logic to determine the price of one of your products. Those sorts of tasks need to be done on your server while it is sitting safely in your data center, and PHP is one of many technologies that can do this for you. PHP is the greatest breakthrough in dynamic web page since the discovery that came 18 minutes before it.

Very quickly, what's a typical PHP architecture look like?

PHP is generally thought of as the central piece of a two tier technology. The diagram below shows a comparison of the most common PHP architecture (on the left) as compared with a traditional three tiered architecture that might be found in .NET or J2EE (shown on the right):

Two and Three Tier Architectures Compared

Note that the browser is usually thought of as part of the presentation tier, even though it is physically separated from the presentation server by the entire Internet. That’s why the stack on the left is referred to as a two-tier model.

So how does industry really use PHP?

In the two tier model, there are typically one or two physical machines in the data center. In the three tiered model, the work load is typically distributed across three or more physical machines. But what’s important to understand about PHP, is that if you look in one of the PHP source files, you’ll see lines of code pertaining to fonts, images, and display-oriented logic, but in that same source file you’ll also typically see lines of source code pertaining to calculating prices or forming SQL statements to directly interact with the database Footnote 2: Note that PHP lets you insert SQL in any source file you want. Java, by contrast, requires developers to import supporting libraries before they can access the database from a source file. That may seem like an unimportant distinction, but that one small difference is frequently enough to remind Java programmers that they should not be inserting SQL into certain files. . Theoretically PHP can be used strictly as a presentation layer technology, but typically in industry it is used for both business and presentation logic.

PHP is unique from its competing technologies in that it was initially created to hack Footnote 3: Remember your blood pressure. small applications together as quickly as possible. J2EE, on the other hand, was initially created for large, scalable, secure applications that would be assembled by large teams of people playing different roles. So even though PHP provides the same very effective mechanisms to properly organize code, the software culture it grew out of is fundamentally undisciplined. PHP code is often very sloppy, unorganized, and redundant, simply because it’s often created by people who have never had a programming class and have never been introduced to disciplined programming practices. That’s not the fault of the PHP language and actually reflects a strength of the language - it’s pretty easy to understand, even by non-developers.

What's all this about "L.A.M.P." ?

PHP is a popular choice for companies hoping to avoid licensing costs. It’s also the most popular choice for small business web hosting providers who almost always provide PHP and MySQL support. MySQL is frequently used by those small businesses, for example, to maintain a database containing a catalog of their merchandise. PHP allows those vendors to calculate prices based on complex selection criteria (like product color, size, and style). PHP (free) is frequently used in conjunction with Linux (a free operating system), MySQL (a free database), and Apache (a free web server) - all free Footnote 4: “It was free. And it was worth it.” Hey… don’t blame us. Mark Twain said it. Send your defenses of PHP to him. - and collectively referred to as “LAMP”.


Can PHP support web services?

Web service functionality is built right in to PHP 5. Creating a web service server with PHP is very straightforward. You create a “SOAPServer” and tell it what function to call when a given web service gets called. Most IDEs have plugins that allow for a simple right click on a PHP routine that pops up a menu allowing you to create a web service out of that PHP function. Calling web service routines from PHP - the client side - is equally straightforward. If you’re using an older version of PHP, the web service support is not built in, so you’ll need an add-on package like PEAR or NuSOAP.


What kinds of applications should use PHP and which should not?

Even though we occasionally poke fun at absurdities in the PHP world, PHP is a very defensible choice for certain web applications.  But what kinds of web applications should use PHP and which should not?  (If you go to php.net, the answer to that question is going to be “PHP is appropriate for everything” - but is it really?)  What are the alternatives? On the other hand, it's just as important to know what PHP is commonly but unfairly criticized for as well.  And it's especially important to know what the most common PHP project mistakes are. Consider spending a few dollars today to avoid disaster tomorrow.  By ordering the book below, you'll get the low-down on PHP and also on a number of other related technologies as well. Don't just settle for the small book excerpt on this web page. Act now to protect your career.