Feb 6, 2011

Why PHP is succeeding in web 2.0?

IMO, there are 3 key reasons:
  1. Apache web server
  2. Developer community
  3. Performance
It may be ironic to write this blog as a strong advocate of Java for more than a decade but the truth is that PHP is succeeding in the web, especially in the 2nd generation web computing. I accept it. I am coding PHP and have 2 PHP books. Do I like the language semantics? Well, it can be improved little bit more and doesn't match Java quality :-) But PHP got all the goodies to build a rich web app.

In a very broader context, we have 3 technology stacks:
  1. Java
  2. LAMP
  3. .NET
I am leaving out #3 as this is not very relevant in the modern web computing architecture. It's mostly for internal IT applications. I am seeing some traction for Scala(as it runs on JVM) and also the some flavors of Ruby & Python. But not going to discuss them as the focus here is about PHP.

Web 1.0

The birth of Java & commercial Web 1.0 was nearly happened at the same time and brilliant engineers of Sun Microsystems was able to make Java as the defacto standard for web with some key inventions like Servlets, JSP, JDBC, JMS and the container model for building & deploying apps. Also, not to forget the external contributions like struts framework, various Apache products, etc.

So, Java model was a super fit for the 3 tier web 1.0 architecture-
  1. Webserver - for static content
  2. Appserver - for business logic
  3. RDBMS - for data storage
Time moves on. Technology evolves. Architecture model changes. Business requirements changes. Scale became an important factor in the web 2.0 for obvious reasons like broadband, #of users, more devices, etc.

Java also evolves. I admit that it doesn't evolve as quickly in the front end web app domain compared to PHP. Java is heavily used in building the back end infrastructure and even data frameworks like Hadoop are written in Java. Java is still a major force in the web architecture and will continue to be...

Web 2.0
The question here is why PHP succeeding in Web 2.0?
In the web2.0 type architecture, there is no clear separation of web server & app server. The static content is mostly served by CDN. Then data is brought closer to the app tier using memcache for performance. So, the architecture is 2 tier: webserver + data storage.

So in this 2 tier architecture model, PHP makes perfect sense as it runs inside the Apache itself as a module. This completely eliminates the need to have a separate tier for business logic for the web app.
  1. Apache web server is a high performance engine. Also it's a modular architecture- we can add modules based on demand. So this is a natural choice for most.
  2. Then having PHP running inside Apache itself as a module helps to deploy the complete app inside the Apache and avoids yet another layer + network hop. This gives good performance.
  3. Like Java, PHP also has a great developer community. Once you have the mass, you will get lot's of support + rich libraries.
In a nutshell, supper rich PHP web app can be built & deployed on high performance Apache web server itself. Then for any back end processing, Java is a great match with REST API.

If you are starting to build a scalable web application, think PHP! If you have any scalable concerns, think whether your app is bigger than Facebook or Zynga! I love to hear it.