A recent Builder.com article ruffled some feathers with its discussion of which Web development languages will reign supreme. To my utter surprise, ASP and JSP were both considered front-runners and PHP was considered a small “holdout,” or a language relegated to hobbyists and not a worthy candidate for enterprise Web development. I took great offense at this, as did other Builder.com members, judging by some of the posted comments.
In my opinion, the reason PHP was not considered a contender is due to a lack of knowledge about it and alternate operating systems used for Web development. Contrary to certain beliefs, Windows no longer holds the majority market share for Web hosting, and I suspect it is steadily losing ground on the Web development side as well.
Why is there no PHP in enterprise development?
Apparently, PHP is thought to lag so far behind ASP and JSP that it isn’t useful, but this just isn’t true. PHP is a powerful language in its own right. It comes with virtually every Linux distribution, as well as Mac OS X. There's no cost in obtaining the building-block tools and software to develop and host PHP code. Commercial integrated development environments (IDES) for developing PHP applications are available—tools such as Komodo (which runs on Linux and Windows) and Zend Studio (a Java application that will run on any OS with a Java Runtime Environment), among others. The fact that you can run a PHP-enabled site on almost every Web hosting environment regardless of what OS the server is running makes PHP even more attractive.
What PHP offers
But forget what’s around PHP for a moment, and think about what PHP offers in and of itself. It is a robust, server-side language that can offer a great deal of functionality, and it can serve pages quickly.
Easy to use
Anyone who has written code in C or Perl or another language with a similar style and syntax will be able to pick up on PHP quickly. Although it's designed for use on the Web, it can be used as a command line language as well. Are you writing a Web application that requires certain pieces of code to be executed every hour or once a day? You can schedule PHP code to be executed whenever you like by using cron or similar schedulers and execute the code from a normal shell script or batch file. No need for the extra overhead of automating a browser launch to view a specific page to execute your event, or relying on visitor hits to tell your system that, at a particular time, certain code needs to be executed. The fact that PHP is so extensible in this area has definite appeal.
Benefits of PHP
I'm not a JSP or ASP guru, and I'm not here to belittle these languages. Instead, I'll focus on the benefits of PHP.
PHP allows you to provide localization to site visitors. When users hit the site, they're automatically provided with the page's default text in their native language, based upon their browser preference. This isn't accomplished using a clumsy file for language translations but using the same capabilities a localized C program might, via a system called gettext. If the requested language file exists, users are presented with text in their native tongue; if it doesn’t, it defaults back to English or any other language you specify. Many localized UNIX applications use gettext as a standard, and it makes third-party translations a breeze.
Easy command line access
PHP supports dropping out and executing command line programs where required. It can generate differences between the last revision of a bug and the current comments to be e-mailed to the owners of the bug by using the standard UNIX diff tool. The PHP code executes diff on two files written to the system, takes that output as input, and generates an e-mail to send. The e-mail is sent via PHP itself.
Those are just two of the powerful PHP capabilities I use within my own programs, but there are others. For example, you can:
- Create simple Flash animations on the fly.
- Create PDF documents on the fly.
- Leverage advanced mathematical capabilities, as well as object-oriented programming methodologies.
- Read and write to local and IMAP mailboxes.
- Use any standard Internet protocol from within PHP. Want to write a PHP-based FTP, Web, or news client? No problem! You can create your own protocol with the client and server written entirely in PHP using standard TCP/IP sockets.
- Implement cryptographic support, as well as support for various database servers.
I find it extremely shortsighted of those looking for the top Web development language to summarily dismiss PHP. I’ve been writing PHP code for years, whether it’s something advanced like my bug tracking system or something small like simply reusing headers and footers across pages. I’ve written semi-static pages in PHP and full-blown multimedia presentations. And I’m not the only one. If PHP is deserving of so little notice, if it’s just a niche or hobbyist language, why is it one of the fastest growing languages used on the Web? If it isn't as powerful as ASP or JSP, why is it being used by high-traffic Web destinations, such as Yahoo, which is reportedly working on a site powered by it?
Developers stick with the familiar
I’m sure that ASP and JSP have their respective strengths, but I believe people use them, not because they offer more firepower than PHP, but because people know them already and want to code in their comfort zone. To dismiss PHP out of hand shows ignorance of the subject.
Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.