Russell and Associates – Forum

September 27, 2009

PHP verus Java (J2EE)

Filed under: Uncategorized — Tags: , , — Vic @ 8:23 AM

The ongoing debate by advocates in both camps is legion.  There are proponents of the scripting (PHP) model that argue time-to-go-live is much faster using php than java.  The Java camp argues that such a statement only makes manifest the PHP advocates ignorance of the Java web framework.

Having developed using both languages, I must say that while both are powerful, Java is hands down more powerful.  There is little you cannot do using the vast array of available libraries to perform the most complex task relatively easily.  And, there are plenty of Java developers in the world to man your project.

Having said that, Java development comes with a very high price.  Most Java-based web frameworks require a tremendous investment in initial training to learn how to use it efficiently – the available beans, servlets, and tag libraries, along with the methods and properties in each class, can be daunting.  The benefit comes once the framework is internalized by the developers – then productivity can be impressive.

PHP is a low upfront cost platform.  The language is intuitive, comprehensive, and interpreted.  Much of the overhead of Java is simply non-existent using a scripting language.

Request/Response – The nature of the web dictates that permanent connections are not established between site visitors and the server.  The stateless protocol that is HTML dictates this structural tenet.   A request is made by a client, the response is processed and delivered by the server(s).  The next request is processed, with the appropriate response, ad infinitum.  Any state fullness is handled by custom constructs – sessions or cookies are the most prevalent in use today.  Any process that can handle the request can deliver the response – the underlying program at the server does not matter to the requester, so long as the response is both valid and timely (<3 sec).

Creativity:  Java, in my opinion, takes away that freedom to quickly deploy a creative solution to a particular development challenge.  Instead of thinking outside the box, Java forces you to remain constrained within the rigorous rules of the particular framework. Since the Java app is running on the server at all times, awaiting a request to deliver a response, there is a great deal of ancillary work to do to add a single class or property.

Deployment:  In certain Java environments, you must compile the complete application, package it in a WAR file,  then move it into the application server ‘servers’ directory.  This can take many minutes given the complexity of the app and the power of the hardware and speed of the comm link.  A few simple changes can result in hours of debugging and testing.

Caching:  I would say that the biggest advantage in using Java is the caching mechanisms that are part of the web framework.  It is amazing how granular caching can be controlled.  There is an obvious performance benefit to this feature when running a very active site.

Testing:  When using an IDE like Eclipse, along with the appropriate plug-ins, one can be very efficient testing and debugging Java code.

Break-Fix: If there is one aspect of Java that really grates me it is the traceback output generated by errors.  Most of the info you get is useless; finding the key output is the challenge.  Once you get the hang of it, you learn to ignore 90% of the output.

Database Access:  Java’s JDBC interface and use of connection pools is time tested and reliable.  The connection open when the application starts, and are available immediately.  There are standard API’s for all major database platforms ready to be downloaded and configured.

Maintainability:  Maintaining an app is where most of the time will be spent on a live site.  If the application is difficult to code, it will be more difficult to de-code/debug.  Again, Java is a bit demanding when something goes awry.  To offset this challenge, very effective log4j logging should be used.

Infrastructure:  This is where the rubber meets the road – how long does it take to set up and configure a new server that can run production code and serve your customers?  Java is a real headache in this regard.  The amount of configuration files you have to update to meet the needs of your environment can take many hours to many days.  There are so many options that it becomes almost impossible to do so on the first try without the help of an experienced Java infrastructure guru.

PHP

PHP is a very comprehensive language.  There are many third party libraries that one can employ to perform the task that you need, that is, unless the build-in functions are sufficient.  I would argue that you can code 95% of a site using the built-in functions that PHP offers.  I do use the PEAR library, which is extremely useful as a DB API.

Testing is typically fast and efficient – particularly when you use Eclipse with PHP extensions or PHP Designer 7 as an IDE.   In PHP Designer 7, you can test multiple browsers without leaving the IDE.  It is a great product that is light-weight, offers Python, JavaScript, HTML, and support for may other languages.

Deployment: You copy your code to the server(s) and it is ready to be run.  That can be a single file or a directory.  There is no up-front compilation to worry about – just test the code and run.

When to use which language?

What skills do your developers have?  If they are Java guru’s, then a j2ee platform would probably be the way to go.  Those skilled in a ‘real’ programming language do not fare well when switching to a scripting language.  The complexity they are so used to is lost.

Also, a very high availability, high hit rate e-commerce web site can benefit from the J2EE framework.  The caching, db throughput, and stability of a java app (once you get it running) is impressive.

Other than the above, PHP has the advantages.  There is little argument against simplicity coupled with power.  Adding an additional os/web server VM to a (non-Windows) server farm is very inexpensive.  The added power and the redundancy of a new server is quite beneficial to any site that has a variable hit rate based on, say, time of year or time of day.

I have installed PHP on Windows and Linux systems very quickly.  That includes Apache 2 and MySQL servers that are required for a fully functional web site.  The WAMP server download (Windows, Apache, MySQL, PHP) takes about 10 minutes to download and install over a fast cable/dsl connection.

Another benefit is Microsofts support of PHP (and Python, another very robust scripting language for the web).  The CLR supports Iron PHP and Iron Python.  Your cost for adding a server will increase (MS Server License), but, if your team is .Net centric with a few PHP apps to support, this might be the way to go.

PHP is easy to learn.  With a decent mentor, a team can get up to speed in about a week.  Java can take a month to get to the same proficiency.  Now these are non-scientific estimates, so don’t flame this author for such an estimate.

Python is another language I have used.  As languages go, Python is beautiful.  By abandoning brackets and using spaces to format the various code blocks, the developer is forced into using good indentation, which results in very readable code.  Python is probably the best language for systems administration – think shell scripting on steroids.  It is blazing fast, robust, and has the advantage of many libraries to extend the base language – many coded in C/C++.  All in all, Python is the most enjoyable language I have yet to use, if that can be said about a programming language.  And, using IronPython and Microsofts CLR, you can use familiar IDE tools to develop.

If you want to get starting using Python, download the iPython application.  It is a command line environment that allows you to test simple to moderately complex code on demand.  A very effective learning tool and sys admin platform.

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress