Reference : fooprogrammer.com
January
30th, 2011 | Author: Indra
With title as above, I am sure to draw flames from both .NET and java
camps. So I want to be clear at the outset by stating that this article is
about developing a web site for public consumption which is typically hosted by
a web hosting company. This is not about developing a web application or a web
site that runs inside a corporate firewall.
Most of my career I have spent programming in java/J2EE and .NET
environments. Like many developers, I also learned PHP, groovy and ruby along
the way. Today, when I think of creating a website of moderate complexity, I am
more inclined towards using a PHP framework rather than using a java or a .NET
framework or any other framework out there. I have worked on java web
frameworks like JSF, Echo2, Vaadin, Grails and recently Play. Similarly I have
worked on Silverlight, ASP.NET and ASP.NET MVC. My conclusion is that, in
overall, PHP frameworks beat both java and .NET frameworks in terms of ease of
development, deployment and even maintenance- for creating web sites with
moderate complexity. Of course, I do not expect you to take my words for
granted. Read on to see what reasons I have to offer:
PHP web hosting options are
superior
Search on the Internet for the best web hosting companies. Invariably
all of them support PHP and the LAMP stack. Almost always, none of them will
support java or .NET. The number of web hosting companies supporting PHP far
outweighs the number of companies supporting .NET and java. Needless to say
that PHP websites are also cheaper to host. You can host PHP websites as low as
$5 a month or even less. Java and .NET hosting are more expensive, in general.
Just because web hosting with PHP is cheaper, however, does not mean
that PHP sites are less performant and have less reliability than their java
and .NET counterparts. It is not uncommon for java and .NET web sites to be
restarted periodically to get rid of unwanted resource locking and resource
hogging. It is far uncommon to restart the reliable Apache Web Server to get
rid of such issues.
You can find PHP support easily on most cloud platforms. Even Microsost
has made it a top priority to support PHP on Windows Azure platform and has
come up with a PHP SDK to access Azure storage and platform functionality.
PHP provides rapid
development and instant gratification to developers
Ever developed a web application using silverlight, ASP.NET ot ASP.NET
MVC? Or developed an application under a J2EE server like Tomcat, Glassfish or
JBoss? Every time you change a class you have to stop the running application,
recompile your changes and then restart the application. Whether you make a
little change or a big one, you will have to go through the following steps:
- First you have to stop the currently running
application. Typically this involves closing a browser window.
- Then you recompile your changes from the IDE.
This may end up compiling one or more project sources.
- Then you restart the application and the
browser window opens up showing your application.
- Then you navigate to the right page in the web
site in order to see your changes.
Do you see something wrong with this? I do. I obviously do not want to
recompile one or more projects, open up my application in a new browser window
and navigate to the desired page every time I want to verify my changes. When I
am developing code, I should be able to see the result of my changes as quickly
and as frequently as possible. With both .NET and java devlopment environments,
I found myself waiting 50% or more of the time on compilation and restart. With
projects having a huge code base, this may lead to nothing but frustrations.
Faster computers usually do not help. Both java and .NET developers (myself
included) are used to such doodle during recompilation – so much so that they
have devloped an insensivity towards it. Therefore most of them will not see
this as a problem at all.
In contrast, when you develop a web site in PHP, you do not have to go
through this notorious compile/build/deploy cycle. You make your changes to a
PHP script, refresh the browser window and you will see your changes instantly.
Add a bunch of new scripts to your web site. You do not have to restart the
server. Just refresh the browser window as usual. This is possible because PHP
uses so called “share nothing” architecture where all resources are discarded
after serving a request.
PHP web frameworks provide
a complete stack sufficient to develop a great many web sites
PHP web frameworks typically provide a complete stack of technologies
required for web development. By complete stack of technologies, I mean
everything from data access on the server side to GUI components in the
presentation layer. Example of such frameworks are Yii, cakePHP, symfony,
CodeIgniter only to name a few. All of them also have good integration with
javascript libraries like jquery.
In contrast web frameworks in java like JSF, Vaadin, Echo2/Echo3,
Wicket, GWT etc. are just client side techonologies for the browser. No doubt,
they provide very good solutions for the presentation layer but you are
responsible for figuring out what server side technology to use for serving
data. For example, you need to decide whether to use JDBC, hibernate, JPA or a
web service for data access. Java frameworks like Grails and Play are an
exception since they provide a full stack of technologies for web development.
However, while developing an website in Grails I found myself hunting for
plugins even to do simple things like thumbnail generation.
Same can be said about ASP.NET, ASP.NET MVC and Silverlight. They
provide robust client side technology but then you are resposible for figuring
out what server side technology to use by yourself – like whether to use
ADO.NET, Linq to SQL, Entity Framework or NHibernate/Spring.NET for data
access.
It is worth metioning that popular PHP frameworks use MVC pattern for
controlling navigation between of web pages and uses ActiveRecord pattern for
data access. I found the ActiveRecord pattern more clean and elegant than
Hibernate, NHibernate, Linq to SQL or Entity framework. The ORM part of the
stack that comes with PHP frameworks are usually pretty robust. For example, I
have not came across something like LazyInitializationException with any PHP
frameworks I have used which I come across often with Hibernate. And I have found
that PHP ORM layers can handle one-1-one, one-2-many, many-2-many entity
relationships very well.
PHP frameworks provide a
low barrier of entry for web developers
There are several reasons why PHP provides a low barrier of entry for
web site developers. The PHP language itself is easy to learn than java and C#.
So newcomers can get their hands dirty with PHP examples quickly. Also the
instant gratification factor of PHP helps newcomers to learn various aspects of
the language quickly. Like java or C#, PHP is a fully object oriented language.
PHP is, in fact, more dynamic than java and C#. Because of its interpretive
nature, PHP is not strongly typed.
Secondly, it is easy to get PHP up and running quickly on bare machine.
You can download XAMPP or XAMPP Lite and can start the Apache web server, MySQL
amd a mail server on your machine in minutes. You need to install an IDE like
Netbeans, PhpStorm, ZendStudio or others for editing you code. Compare this to
setting up your development environment in java and .NET. In java it is not so
bad after all – you have to download the right version of the JDK and then
install your favorite IDE like IntelliJ IDEA, Netbeans or Eclipse before you
start developing your web application. Setting up the development enviroment in
.NET is the worst. First you have to install the right version of .NET
framework on your machine which may take anything from half an hour to two
hours. Then you have to install Visual Studio which may take several hours. I
found that I had to spend half a day or more setting up my development
enviroment in .NET. I had a pretty high-end machine with 4GB of RAM.
No DLL or jar hell
It is a great relief that I do not have to deal with DLL or jar hell
while devloping a web site in PHP. While developing an application with
NHibernate/Spring.NET, I came across an exception that does not realy tell me
what the problem is. I spent several hours browsing Internet forums to see if
others have similar problems, only to discover that I did not have the right
version of one DLL. Then another round of wild google chase to find the right
version of the DLL.
I encountered similar issues with grails when started developing a web
site that used several grails plugin. When one of the plugins failed to work, I
had to browse the Internet for several hours to find the solution. And guess
what the solution was. Use the right version of jar file because the plugin is
not compatible with any other version of the jar.
When I deveop a web site using PHP, I do not come across such issues
frequently because, like I said before, most PHP frameworks provides complete
stack of technologies and I do not have to use a whole lot of third party
extensions. Even in cases, where I used third party extensions and there was a
problem, the problem was much easier to resolve because of scripting nature of
PHP.
29 Responses to “Top five
reasons why PHP is a better choice than java and .NET for building most public
web sites”
- Mr Z says:
Nice post. Not too many
seem willing to be kind of objective about the tools available to build a
website with. I agree that your view here is not perfect for business web
application behind corp firewall, but it does apply to a huge number of other
websites. I also think there are specific instances/requirements where PHP will
not be the best choice, but in the large number of situations it is a great
choice.
When you are stuck using a
particular technology, you end up being stuck with a limited number of
solutions – only tool is a hammer, all problems are nails. I’ve been looking
around casually for someone that compares PHP to Grails or others in a
technical feature list kind of way, and perhaps how you implement great feature
xyz of one environment in the other. Interesting note on this, looking at
Grails GORM and what the programmer has to do to use it and how that would/can
be implemented in PHP as an example.
There is always lots to
learn. Good post.
- Coder says:
- Jacques
Marques says:
Excellente points, I agree
with you in all, and more PHP is far more easy to programm then .NET an Java.
And Python web is a better
choice than Php
- Mikael says:
I personally feel that play
addresses most of these points pretty well.
If anything it might need a bit more time to mature, but on the other end it
provides most of the flexibility available to PHP with the whole Java echo
system available.
- peter says:
>Java and .NET hosting
are more expensive, in general.
What about Google
Application Engine? (GAE) You can start hosting Java websites/applications
there for free.
Well, GAE is pretty cool
but it lacks alot of things including one major thing which is the DB, I know
you are going to tell me to use the Datastore, but it lacks the benefits of a
true RDBMS
One deadly limitation of
the datastore, that you can’t use the OR in different fields
for instance you can do this: SELECT * FROM tablename WHERE field_x = 1 OR
field_x = 2
but you can’t do this: SELECT * FROM tablename WHERE field_x = 1 OR field_y = 1
Amazing post, I don’t know
how java developers have the patience for the process mentioned just to change
a little thing.
- peter says:
>Whether you make a
little change or a big one, you will have to go through the following steps:
This is not true. Without
any additional tools I can change JSP pages, Facelets and other resources. I
can also change code -within the method body- of classes. After a refresh, the
changes are there.
If I want to change the
structure of a class without having the restart anything, I simply install
JRebel. Works great.
(p.s. it’s also Java EE,
not J2EE, that’s a very old term)
I completely agree with
you. PHP is very easy to start up, develop and host compared to the other
environments, especially when using a framework. I also find it speed wise
performing better in general.
Final note, from my
experience is that PHP also has better community adn documentation on the web
which helps development time.
Great post!
- Indra says:
First of all, thanks for
all the responses.
Coder and Mikael, I agree your comments about Play. Play is the only framework
that has given me the same experience as PHP. However, Play framework is yet to
mature. I am still experimenting with Play and hope to write about Play in the
near future because I like many things about that framework.
Peter, while your points are true about JSP, it is not true for all java
classes in the application. For example, I tried to create an application using
Vaadin and Grails, and every time I change a class in the UI layer, the application
will restart in the development environment under IntelliJ IDEA. I have not
used JRebel but will take a look at it to see if that addresses my issues.
Also yes, you can start
hosting in GAE for free and pay as you go on. However, I find GAE to be a
considerably limiting environment. First of all, GAE does not support
Hibernate, the most widely used ORM tool in java. It has limitations on the
number of files. Many java EE APIs are not available. So on and so forth. But
for starter it can be a good option if you can live with these limitations.
Indra
I had a discussion with
colleagues on this exact topic a couple of days ago, and was promoting Php. I
couldn’t pack my arguments nicely at all, but I no longer need to. I’ll just
point them to this post
I have bookmarked your site
for future referrence! Greetings.
- Raphael says:
Java and .net have tons of
full-stack integrated web frameworks for rapid development, no jar hell, no
verbose configuration, easly start and entry level. I’ve been using grails for
2 years and deployed 4 projects to Google app engine so far.
I’ve worked with php for 3
years and in java for 3 years and in my opinion, using rapid framework in java
provide much better tools for development, deployment and scaling.
I think your knowledge of
java and .net ecosystem is very limited. Check out play framework, Lift-web,
Scalatra, Asp.net MVC, Grails, Jython/Django, JRuby/Rails, Wicket.
GAE/J apps can use JPA wich
is modeled after and in fact vary similar to hibernate. Uou can also host in
AWS and several other cloud vendors where you pay as go which reduce costs
wuite a lot.
I fully undestand the
advantages of python, ruby, php agaist java/.net but the arguments you used are
very weak.
- peter says:
@Indra
I didn’t use IntelliJ, but
using Eclipse and a server adaptor that does incremental deployment (most of
them, but make sure you use/install the right one) nothing ever restarts when
you change code inside a method of a class.
This is a feature of the
JVM that underlies each and every framework, including Java EE itself. It
therefor doesn’t matter which class and where you change it.
But note its limitation.
Only code changes inside a method is supported this way. If you change the
structure of a class (add, remove or rename a method, etc) you need JRebel.
About GAE, JPA works out of
the box on it. Many programmers prefer to use the JPA APIs instead of the raw
Hibernate APIs anyway. Web frameworks like JSF and quite a few others also work
on it. Many existing libraries are being patched to work on GAE.
So yes, not -everything-
works on it. But -a lot- does, and all of this is for free.
- Indra says:
Raphael, your answer is
very typical of developers who focus only on the solution but not on the
problem. If PHP can do the same thing at a much lower cost why should not I use
PHP? May be I did not articulate myself carefully. Java and .NET have large
ecoystems and toolings. What is so great about that? Both technologies are also
responsible for a lot of failures in the corporate world.
By the way, I have used
Gails and deployed apps on Gigenet cloud. Not a big deal. Grails GORM and
configuration-less Spring integration are great but I miss the instant
gratification factor when I change a script in Grails. When you change a gsp
file, Grail application will not reload but when you change a service class or
some other class it will reload resulting in stalled browser sessions
frequently. I found this annoying. Only java framework that has addressed this
to my satisfaction is the Play framework. But I do not think Play is ready from
prime time yet.
Grails has a good
templating system but very few HTML/Javascript helpers in the UI layer. It does
not even have a simple datagrid component (sure you can use jquery and get
one). Compare this to a PHP MVC framework like Yii which has support for a
GridView(with ajax of course), DetailView, a dropdown menu and whole lot of
HTML helpers out of the box. Also look at the way documentation is organized in
that site and see how quickly everything is searchable – http://www.yiiframework.com.
Thanks
Indra
Its hard for me to find
useful blogs nowdays but when i saw this i knew i was in the right place, I
finally have time to clean up the house.lol Your a lifesaver.
- Sorokan says:
PHP has it’s advantages,
but what’s about it’s disadvantages? It’s simply not a well designed language,
it’s rubbish. And the framework? Zend is a nightmare. Debugging is a nightmare.
Its 100 times slower than java. It’s inconsistent all over the place.
Every real programmer that
is more than a web kiddy hates it, and there’s a reason for that
>>It’s simply not a
well designed language, it’s rubbish.
The language does suck in a
lot of ways; however, I wouldn’t go as far as saying it is complete rubbish.
Also, it gets better all the time. In fact, PHP has closure support and traits
on the way.
>>And the framework?
Zend is a nightmare.
Actually, there is only a
framework called “Zend Framework”, not Zend. Zend is a company. Also, why is it
a nightmare? And compared to what?
>>Debugging is a
nightmare.
Depends on the person that
developed the code. This can happen to a Java codebase as well. This statement
is pretty general and subjective.
>>Its 100 times
slower than java.
Depends on what you are
trying to accomplish. If raw speed is all you ever care about in the real
world, then may I suggest you convert all your existing Java code to C or C++.
>>It’s inconsistent
all over the place.
Yes, it is. No debate
there.
>>Every real
programmer that is more than a web kiddy hates it, and there’s a reason for
that
Not all “real” programmers
completely hate it, but most competent programmers that continue to use it are
annoyed by some of the inconsistencies and inelegances; however, know how to
side-step them to get the job done well.
Indra I might be biased but
agree with you, PHP is better choice for less complicated websites and even
when it comes to complicated one most of the time we end-up using heterogeneous
technologies not just one..
You can see FB is one of
them.
- Indra says:
Well, my comments are about
a public facing website with moderate complexity. For most such web sites a PHP
framework provides everything you need to create such a site. Again PHP is not
a rubbish language. It has evolved. Sorry, it is an object oriented scripting
language which is more dynamic than both java and C#. For example, in PHP you
can add a method to a class at runtime which you can’t do in java or C# without
byte code instrumentation. PHP is not as object oriented as java and not as
dynamic as ruby but is good enough for the web. It is simple and easy. What’s
is so wrong in being simple and easy to learn. Are we not all striving for
simplicity?
- Indra says:
A lot of java/.net
programmers got irritated by the fact that I suggested that the PHP stacks to
be more complete that java and .NET frameworks. This was unintentional. My
point was that PHP frameworks are complete enough to do the job of creating a
web site with moderate complexity. I program myself both in java and .NET and
understand fully well the advantage of an enterprise framework in building a
robust and secure application. I just do not want to use the same hammer to
drive every nail.
The layout is what really
caught my eye, then the i looked at the writing and i think you did a very nice
job. Good work:)
- franpas says:
Good post! There are really
good points on the comparison. Although I’m biased to strong typed languages, I
still haven’t found a good option (phpunit??) to detect type changes before
running the application and avoid a crash. In that sense, I don’t know which
language offers a better aproximation (among php, ruby or python)
Thanks for the post!
@franpas:
Yes, PHPUnit will do all
you need and more in PHP. If you are doing enterprise work in PHP, you
absolutely want to be using PHPUnit.
Your question regarding php
vs ruby vs python…well, they all have their strengths and weaknesses; however,
if I knew years ago what I know now, I’d likely have learned Ruby/Rails
earlier.
I totally agree with you ….
PHP is the king in the Web-based projects…
Let’s stop arguing about this comparison and see around you in nearly every
website you hit daily … which language are they using … Facebook,
Wikipedia,Yahoo,YouTube…etc
Nearly all supporting
forums in nearly every aspect is written in PHP …
PHP is everywhere, free, a
huge supporting community that I don’t think any other language can beat it …
By the way … try writing
those words on google and compare the no of results only !!!
php language
java language
asp.net language
ruby language
Simply great!!
Nice post and comments… I
really want to say one line,
“A skilled/experienced
programmer is required to make a language secure, Because each language having
some set of limitations, we can’t figure out a language to be insecure instead
of blaming a unskilled programmer”