Php vs java

Almost every week or so, someone asks me: Why PHP? Apparently, you are doing Java too. So why not Java? Do you regret the fact that you wrote Drupal in PHP?

The answer?

No, I don't regret the choice of PHP. Both languages will get the job done, but Drupal's main target audience are not conservative verticals (government, healthcare, banking).

The web is built by millions of individuals, many of which are amateurs. They continuously update, tweak and rebuild their websites. Scripting languages like PHP lend themselves to that, and are widely available at affordable cost. Sun, on the other hand, failed to make Java accessible to amateurs.

It would have been very difficult to get critical mass if Drupal was written in Java.


Itkovian (not verified):

One might add that the way in which so-called scripting languages are used lends itself to a faster write-test-sequence. The same can be said for languages such as perl and python. They are perfect for so-called prototyping or rapid development cycles.

Of course, the drawbacks to such languages are well known, the lack of types being one. Strong statically typed languages are usually less error-prone at run time. But no one can deny the fact that PHP has made web development more accessible. Undoubtably, the level of de code will take a hit when non-professionals are at work, but as we all know, being a professional is no guarantee for decent code.

But why the whole Java vs. PHP question load? IMO, most languages are suited, and oftimes made, for a certain category of tasks. It is wrong to try and use a single language for everything. Of course, as languages are Turing-equivalent, they can ultimately be used for all the jobs another language was used for, but writing e.g. Doom in 'sed' is just a bad decision. If you decide to do it anyway, the purpose should be fun. The same goes for websites. If PHP suits your goal, use it, if it doesn't, then don't. But IMHO Java for website development is most often a major overkill.

Of course, enough bits have flawed argueing over these things. So I'll leave it at this.


Each programming language has its advantages and disadvantages. I deliberately tried not to get into technicalities because any attempt at comparing PHP to Java is bound to be (1) incomplete and (2) subjective. Static type checking, the example you used, is only one aspect of many and has both advantages and disadvantages depending on your priorities.

Luc Van Braekel (not verified):

Interesting post, and I agree with it.

But you don't mention why those "conservative verticals in government, banking and healthcare" are choosing Java. Isn't that because of:
1) the better scalability of Java;
2) the fact that Java is better suited for complex mission-critical applications, for the reasons that Itkovian pointed out.

If scalability is an issue and hardware cost is not an issue, I would opt for Java too.

On the other hand, PHP runs very efficiently, even on small hardware footprints, is tightly integrated with the web server, and is better suited for agile development by amateurs.


What makes you think Java has better scalability?

The Java community has an unhealthy focus on the scalability of non-Java solutions. Some of the most popular websites in the world are written in PHP (eg. Wikipedia, Flickr). Scaling a PHP application means scaling your webserver (typically Apache or Lighttpd) and scaling your database server (typically MySQL). These problems are solved and well-understood.

Besides, if your Java-based web application uses a database server, you'll have similar issues to deal with. If you have to scale your database server, it is not because you are using PHP or Java, it is because you have a lot of data to deal with.

Itkovian (not verified):

I think that the scalability issue is often misunderstood. People claim that Java scales well, because it comes with a load of OO paradigma's and tools that supposedly allow for a better maintainable codebase - meaning that the scaling is inherent in the maintainability. However, writing maintainable code is not only a feature of the language, it's mostly a feature of the programmer. It's quite easy to write obscure, non-extensible and unmaintainable code in Java. The same goes for any language. I've seen Java code that was written superbly, and I've seen PHP code that was written superbly. And I've seen the other side for both languages as well.

The issue remains that people often criticise a language decision without understanding the arguments they bring up. And as the British say: the proof of the pudding is in the eating. I think PHP has proved to be usuable for large-scale projects - as long as the programmers adhere to good coding practices.

Iqbal (not verified):

It would have been very difficult to get critical mass if Drupal was written in Java.

Dries, I 100% agree with you. One of the most important things that make Drupal success is the programming language used to build it (PHP).

I'm not talking about technical issue. Both PHP and Java are great languages. I'm talking about availability (PHP is widely available at affordable cost). Almost every hosting service has PHP support. It makes Drupal available for everyone.

Dries, thank you for the Drupal. It's a great software. We are going to use it for our server.

Anonymous (not verified):

It would have been very difficult to get critical mass if Drupal was written in Java.

It's not that it would be difficult, it just means that not every Tom, Dick, and Harry that read a book on Java with no education or experience could contribute. I've seen Drupal, and Joomla, and other open source CMS products. In my opinion, there is a lot of garbage code and components out there that no one reviews and so the standard of coding has become a "read-a-tutorial" on PHP and I know what I am doing type of thing. Sql-Injections, form-hacks, they are all over the place with. Anyone can write PHP code (not necessarily good code) but not everyone can write Java code.

Daniel Zhou (not verified):

Dries, I also agree with you that Drupal should be written in PHP rather than Java. However, I hope Drupal could provide a Java-Drupal library so that people can develop Drupal modules using Java. There are tons of tools written in Java such as Lucene that could make Drupal more powerful.

Sebastiano Costa (not verified):

In my opinion any programming language has pro and cons and it's stupid to say "this language is better than that one" or "anyone can write code using PHP but only someone can do it in Java" ... bla bla ... Flickr, Facebook, Wikipedia and many other thousands successfully applications have been written in PHP and what is great is the idea behind (the target) not the tool !! So let's do a comparison between the various languages but just to let people decide which one to use (according to their needs) not to say this is the best and this is the worse ! These discussions are for the children !

Anonymous (not verified):

I think the point is, we all know Java would be better for damn near anything, but no-one has Java.

I pay $5 per month for shared web hosting. If I want to install things like blogging software, it has to be PHP. That's just all there is.

If I wanted Java, I'd have to pay more or go somewhere else. *everywhere* has PHP. There's never any question of it.

Those of you talking about Wikipedia and Facebook etc ...

They probably got started on PHP not because it was the best tool for the job in some theoretical computer science sense, but because they happened to know it. Once they had a quick prototype scratched out, why start over?

Just because PHP *can* do it doesn't mean it's ideal. And even with facebook, PHP is just a front-end language for writing up the look and feel. They don't build their backend in PHP. Not only that but I've heard they even modify mod PHP to optimize it for their system.

David Legg (not verified):

As a Java developer I look somewhat enviously at the PHP fraternity when it comes to supporting small business sites.

You seem to have lots of ISPs providing PHP ready server platforms at relatively cheap prices. Additionally because of the huge developer base there seems to be reliable software to do just about anything you want.

Java is not that well catered for by ISPs. It needs lots of memory and ISPs are reluctant to provide it in useful quantities without it becoming uneconomic.

You could get round this by renting a small dedicated server or even a virtual dedicated server from an ISP but that isn't practical for customers with small sites. In any case you would then have the problem of how to backup the machine because most ISPs leave it up to you to backup your dedicated servers. Similarly, my experience with virtual dedicated servers shows lots of stoppages due to other clients hogging resources.

Richard (not verified):

Hi Dries,

First of all I'd like to thank you. I entered web development just 6 months ago and I've managed to create a sucessful site about the Japanese island of Ishigaki which I live on thanks to Drupal and I've loved every moment of the process.

I come from a background of real-time software engineering in the field of automated lab devices and consequently I know c++, c# and a bit of Java. I've just started to mess around with php as I need to write a module and to be honest the language scares me (much more so than c++ or Java ever did). The lack of type safety makes me cringe and in my view the language itself lends itself to the production of hacky, poorly-organised code. The limited number of testing and development enviromnents is also of concern to me - developing c# / in visual studio is an absolute dream, particularly when it comes to debugging and test harness integration. There is simply nothing comparable when it comes to php development.

My point about a .net based version? Would this be beyond the realms of reasonable thought?

Dimitri Uwarov (not verified):

Hi Dries,

I absolutely agree that it depends on what you aim to do with the language and from your skill as programmer. I also happen to use both languages often. In my opinion, PHP is better for community whereas java is better for enterprise. Let me illustrate...

I am a java professional, but for my site ( i used PHP.

Not Drupal, but WordPress and things like phpBB.

I don't regret this choice and i still love doing hardcore java.

The reasons I would use PHP for many small to middle projects are:
- community is large, most problems solved in simple way. Much code can be used directly. No dependencies, just php.
- hoster are cheap, fast, good. With java it gonna cost you and there are issues which are simply not there with php
- php can be used directly, so i see what i do and i see the state of my application. In java, your webapp or some jar may have "big bug", but you will see it after days because your tomcat crashed with crypticall "out of memory".

Java is good for enterprise.

Java is inherently integrated, and PHP is "rather separate code which just happen to work together".

That is why enterprise is better off with Java if it wants the integrated infrastructure as whole. I would definitely pick java for that.

Also, there are lots of professional entities like consulting firms, or big players like IBM, they all provide Java experts, teams and solutions. That cant be said for php, which is true community and open source. Enterprises NEED long term guarantees for there projects. Bigger enterprises NEED bigger partners to ensure there projects will work and be supported longtime. There is no such option with PHP...

// Dimitri

Anonymous (not verified):

Hi Dries,

Thanks for your ongoing work on Drupal, which runs many of my sites, even if I obviously have some grave concerns about certain aspects of Drupal coding culture and the APIs.

I am an advocate of strongly graphical software engineering, and a long term fan of UML+Java (and UML+C++ and UML+XML), and I have worked with UML (and the more recent systems engineering variant SysML), and I even worked for a UML+SysML tool vendor. I am also an advocate of strongly document-driven engineering, with graphical UML and SysML as a bridge between text-based statements of requirements and system descriptions (not just for software engineering, also for systems engineering).

Although a degree of reverse engineering of PHP to graphical UML is possible, and some forward engineering of UML to PHP is possible, the fact that it is untyped is a serious impediment to integration with graphical UML (although I believe that one could introduce annotations with type-hints to aid reverse engineering of PHP code).

BTW I am also by now a pretty handy PHP coder, and I've programmed for over 30 years. I use and teach however mostly advanced graphically driven UML+Java and UML+XML, and also SysML-based systems engineering.

I am rather openly critical about many aspect of Drupal (while I appreciate the accessibility that PHP affords and I benefit from the contributed modules community), and I hope through these projects to make a case for far more object-orientation in Drupal 8 (it is too late for Drupal 7), and more integration with graphical UML engineering.

I have recently announce 2 new projects for Drupal to help address these matters, and I invite you to read the announcement pages:
[Announcement] The snippet-driven Drupal documentation UML Parsing Analysis project (DrUML)
[ANNOUNCEMENT]: the JUML project: a Java mapping of Drupal under UML Parsing Analysis of

And there is a mini announcement page and explanation on

Announcing dedicated project DrUML for snippet-driven UML analysis models of Drupal documentation

These projects, although UML-oriented, are not only conceived to benefit those fluent in UML, and certainly the focus is not to replace PHP-based Drupal with a Java version; the emphasis is on developing a systematic analysis layer for Drupal6 and Drupal7 that can be used to improve Drupal8, and to convince you and other core Drupal developers to finally embrace some crucial object-oriented technologies and selected design patterns that are sorely missing in Drupal6,

I believe I can bring something very important and useful to the Drupal community that likely nobody else in the world would, and I believe that Drupal does need this help. I would be very grateful for your feedback (and I realise how confronting my criticisms of Drupal have sometimes been), and I would very much welcome financial support for this effort, perhaps from one of the Drupal "distribution" groups like Acquia.

Dr Darren Kelly (Webel IT Australia)

Scientific instrument control, modeling, and simulation expert.
Nuclear scientist (yet environmentalist)
Developer of the amazing Drancing accelerometer
body music synthesis system

And seriously devoted UML and SysML evangelist.

Anonymous (not verified):

I'm trying to push a drupal based KM system in my workplace. The IT guys want to write this in Java. However any other web portal they have crated is slow and not very nice to use. This would also be by far the biggest project they have undertaken. Hence I have been looking in the open source arena in particular Drupal. We have opened discussions with a PHP developer. One of the points he has made is that a Java system would be slower as Java is notoriously slow.

Could anyone shed any light on what he means by this? Would using Drupal produce a faster system?