RoboGeek

RoboGeek's (David Herron) Weblog: co-developer of Robot and several other things related to Java testing.


« The bottom level of... | Main | Re: PHP versus JSP/e... »
20050308 Tuesday March 08, 2005

PHP versus Java/JSP/J2EE/...

Last weekend I decided to try a bit of PHP programming. I wanted to see what the language was like, whether it was any easier to create pages, etc. I'm a little experienced with JSP programming, and in the long distant past I once wrote my own page template engine around TCL because at the time there was nothing else available.

To compare PHP versus J2EE is utter nonsense, because they serve completely different purposes. J2EE is very rich in capabilities, ones that appeal to large enterprises or very busy web sites. These are capabilities the PHP programmer can only dream of, because PHP doesn't provide anything like it.

It seems fair to keep the comparison to the closest analog to PHP, namely JSP.

Another note is that obviously I have a Java bias, given that my job involves working on Java.

With that out of the way ... what do I think?

Learning curve

Well, PHP is pretty easy to learn. I simply stumbled my way over to php.net, found the online manual, and read a few things, and said "hey! that's easy" and started coding. Within a few hours I had a website whose pages are dynamically built from a database. I'd previously written some JSP pages to use that same data, displaying it in the same format, so this is a fair comparison.

The JSP pages I'd written also went very quickly. Except, by the time I wrote the JSP pages I'd already gone through the steepish learning curve to learn JSP and JSTL programming.

Here's the rub with JSP, that somehow JSP programming is somewhat difficult to pick up. I think it stems from a couple places: a) the servlet/JSP specifications are written in a difficult legalistic style, and b) there's baggage from the early servlet history.

If one were to stick purely with JSP and JSTL then programming JSP's is pretty simple. Even writing new JSP tags is very simple, if you use the new XML-tag file format. But unfortunately the books that teach JSP and JSTL have to talk you around all the old baggage.

In comparison I found the PHP model and documentation to be very clear and easy to understand. Like I said, after a couple hours I had some pages going, having never done anything with PHP other than glance at a few source files. That's a pretty easy learning curve so far as I can see.

Capabilities

I find great fault with PHP in its capabilities.

First PHP ignores the MVC model. The "business logic" is hopelessly intertwined with the presentation. In the pages I've been writing, the core of the presentation is embedded in strings in echo statements. This in turn makes it very difficult for a WYSIWYG style web editor to do much to help you lay out your pages.

By ignoring the MVC model, this relegates PHP programmers to indirectly coding the page layout, rather than designing the layout through direct manipulation in a WYSIWYG editor. By comparison, JSP (if you use the modern JSTL or STRUTS approaches) can show quite a lot through a WYSIWYG editor, and dynamic pages can be designed through direct manipulation rather than indirect coding.

Second, PHP as a language isn't very scalable. Since JSP resides atop Java, you have a tremendous, modern, object oriented programming language with tons of software modules ready to be tapped upon. PHP doesn't have this backdrop, hence this world needs to be reinvented for PHP in order for a PHP programmer to use it. Also object oriented programming is a new feature to PHP, which I've not studied yet, but I expect since it's a new feature layered on top of a non-OO language that it's likely going to be clumsy.

Market realities

On the other hand, it's clear that PHP is very popular with some. For example I've spent a lot of time looking at hosting providers. I know it's trivial to find a hosting provider that offers PHP service, and that it's very difficult to find one offering JSP service.

That distinction has given me a lot to ponder. The conclusion I've reached is that the hosting providers have razor thin margins and need to keep costs pared to the bone. This means open source solutions are great for them, because the cost is minimal. Now, the Linux+Apache+MySQL+PHP (LAMP) is very easy to install and relies completely on open source software packages. Comparatively Linux+Apache+MySQL+Tomcat+Java is pretty darned difficult to install, if only because the mod_jk (or is it mod_jk2) installation is a mess. The installation process is very poorly documented, and it is being completely unclear whether one is supposed to use mod_jk or mod_jk2.

Putting myself in the hosting providers shoes, it looks like Java/JSP is too difficult and possibly with a low payback. Even if one were to use a different appserver than Tomcat it's almost certainly going to involve money, which the hosting provider can't afford (razor thin margins).

So in summary I think JSP is capable of a lot more than PHP, but hampered by a steepish learning curve and a difficult installation process. (2005-03-08 11:05:34.0) Permalink Comments [7]

Trackback URL: http://blogs.sun.com/robogeek/entry/php_versus_java_jsp_j2ee
Comments:

Two comments:
  1. There are MVC packages to PHP. Smarty and Felxy for example. MVC is really easy with PHP.
  2. The comment about libraries in Java but not PHP is strange. Did you look into pear.php.net? Hotscripts.com?

Posted by 80.179.73.38 on March 08, 2005 at 02:02 PM PST #

When looking at php you need to look past the basic php install. There are many open source projects that build on php and make it much nicer and more robust. For example the PEAR libraries (installed by default on a lot of linux distros now) give you a lot more functionality. The best project to use along with PHP is the Smarty template manager. The Smarty templates seperate code and markup better then anything else I've used. Please check out PEAR libraries to give you more functionality (esp DB, and XML) and then check out Smarty for great code seperation. Chris

Posted by 129.174.172.26 on March 08, 2005 at 04:03 PM PST #

"It seems fair to keep the comparison to the closest analog to PHP, namely JSP." It doesnt seem fair to compare your first raw php page ever written to something you would do with JSP + other frameworks. PHP can do MVC, with many MVC frameworks out there already. It doesnt force you do use a particular framework, just as you dont have to use Struts with JSP. "Second, PHP as a language isn't very scalable". Another misconception, this time about PHP's scalabity. You have written your first little php page and now you say PHP isn't scalable? PHP does scale, its a shared-nothing approach which scales differently to how you would scale a j2ee application. See : http://www.oracle.com/technology/pub/articles/php_experts/rasmus_php.html Look at the big players like yahoo and friendster. They use php and it scales well.

Posted by Steve Kurzeja on March 08, 2005 at 05:04 PM PST #

Nice article. I've been pulling together a number of similar articles into this very subject. If you're interested in seeing the other articles I've got then you can check it out here: PHP vs Java Comparison. Personally I'm a PHP zealot although my 'upbringing' is very much a Java one.

Posted by Doug Bromley on September 22, 2005 at 04:04 PM PDT #

Dear David, My question is regarding a php framework using the MVC model. I am looking for a PHP rapid development environment that allows me to implement MVC design with Object Orientation architecture. I would prefer to find open source framework but as you said there are a few out there. I tried cake and it was pretty unstable thus far. I am looking at Mojavi now but I wanted your professional opinion so I am not wasting precious time. PHP is everything I've needed so far but now I need to develop in a framework (prefer on that has some existing commonly used namespaces). Your time and thoughts are greatly appreciated. Regards.

Posted by Steve on January 11, 2006 at 01:32 PM PST #

Well Steve, I do as little as I can with PHP and in general do little in the way of scripts/software to dynamically generate web pages. I've been dabbling in this for years (nearly a decade). The only PHP related thing I have deep experience with is the Drupal content management system. I like Drupal's feature set, and to a large extent I like the implementation as it's pretty flexible. What I don't like about Drupal is the community doesn't value keeping a stable API to which modules can be implemented. For example they are currently in the process of getting 4.7 out the door, and have put a "Forms API" into the system which completely breaks the old modules and most of the modules have to be ported to use the 4.7 Forms API. Sigh.

Posted by David Herron on January 11, 2006 at 01:46 PM PST #

Thank you for the incredibly quick reply!! I appreciate your insite regarding Drupal, it will definitely assist me with my project as I was considering it. In case you are interested I did find a link to a list of the php frameworks but there are no reviews as of yet - a nice list though. The link is: http://www.phparch.com/discuss/index.php/m/7697/4ebd74173a69ecc2d6f39ec570f36ce1/#msg_7697 Thank you again, your time is appreciated. Happy New Year David!

Posted by Steve on January 11, 2006 at 02:03 PM PST #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed