« Random thoughts: scripting in Java | Main | EMEA Architects Journal 2: less architecture, more practice »

The reason PHP is more popular than Java: it's safer

I really don't understand why PHP, etc. dominates the free/cheap hosting solutions. Tomcat is a production class Servlet Container and JBoss easily holds it own against the commercial application servers. Then for database you can always choose MySql although personally I'd go for Postgres (this has the benefit of being similar to Oracle should the client want a transfer). - Mike Cogan

I'll take a stab. It's because Java/JVM wasn't designed with multi-user environments in mind. LAMP solutions leverage the (usually *NIX) operating system to manage user processes.

The JVM by comparison is a single user environment - code is running pretty much as root, which is what you'd expect given its use-case evolution (devices, websites, middleware). I think it would be too easy to hose a server running on a JVM if anyone could deploy code in it. My hosting provider emails me if I have more than two processes running for a period, that's fairly easy to do from the OS. Not so easy is to email me if I have more than two Java threads running or if I have deadlocked the JVM altogether. The (usually *NIX) operating systems have been doing this well for decades so that's entirely sensible to build on them. But Java only has the JVM, so you have to build all the user controls again from the ground up.

The alternative, to run multiple JVMs won't fly - memory gobbling plus you have to manage inter-JVM comms from the server to your Servlet and back again (Servlets are not designed for this, in fact, quite the opposite - their initial selling point was running them in the same process as the server). Tomcat, JBoss and friends (UCL? For multihoming? With that reputation? Are they quite mad?) strike me as too flaky for multiuser environments until the JDK ships with Isolates.

I'd love to know how the few Java hosting providers that do exist manage to keep things running at all.


April 20, 2004 05:16 PM

Comments

Carlos E. Perez
(April 20, 2004 06:59 PM #)

I agree, that's why I was completely dissapointed when Isolates were taken out of Tiger 1.5.

Carlos

Chris
(April 20, 2004 07:01 PM #)

I agree. These are also the reasons (running as root, heavy processes) -- plus Perl's ability for users to reach into the symbol table across namespaces -- that more hosting providers don't run mod_perl, which is a shame.

Lasse
(April 20, 2004 07:24 PM #)

I believe the readily available PHP-oriented hosting products such as cPanel have some part in PHP's dominance in shared hosting.

Dave
(April 20, 2004 07:55 PM #)

Idiots. PHP is about 1000 times easier to learn than Java and every script master in the world can figure it out. ISPs are trying to get customers, not software developers and PHP just makes sense. I'm sure your average product manager at an ISP gives no thought to some security mumbo-jumbo.

Jeff Moore
(April 20, 2004 09:26 PM #)

The advantages that PHP has over Java for web development:
Lower barrier to entry
Dynamic typing
Simpler hello world
Cheap widely available hosting
Deployment is a simple file copy
No compilation
No class path
Focus on a single domain (web)
User annotated online documentation
Commonly installed by default with Apache

Danny
(April 21, 2004 12:23 AM #)

I'm starting to think Python offers the best of both worlds. I expect this comments thread to last ;-)

btw, nice makeover.

Hey
(April 21, 2004 04:59 AM #)

PHP is more popular because there are way more simple web apps and way fewer large scale enterprise apps. PHP is used on simple web apps and Java on the large scale enterprise apps.

Frank Nestel
(April 21, 2004 08:31 AM #)

Concerning root rights: Cauchos Resin is demonstrating, that you can setuid the JVM. Multiple isolated apps in one JVM would help a lot though. I'd prefer Java over PHP, cause just too often a easy hacked little App grows into a messy non maintainable something. Of course befor you start with JSP, rather use PHP :-)

Danny
(April 21, 2004 10:31 AM #)

Frank - I've got an account with a web service provider which includes Resin, unfortunately it very rarely works due to malconfiguration. PHP on the other hand seems to work out of the box. I'd much rather use Java, but it looks like I'm going to have to learn PHP (one day) if I want stuff live.

In favour of JSP is that you can hack simple PHP-like code but then extend it with more sophisticated classes later.

Bill de hra
(April 21, 2004 10:44 AM #)

Frank, I didn't know that about Resin. Cool. I have to say the Resin is an excellent server - Scott Ferguson knows his stuff.

script kiddie
(April 21, 2004 03:49 PM #)

PHP is for script kiddies

Java is for enterprise developers

If you need to do a mailform use PHP

If you need to have your S35 IBM Monster exposed to the web use Java

If you can afford a colocated server use Java

If you can afford a $4.99 a month virtual host, use PHP

Damien Bonvillain
(April 21, 2004 10:58 PM #)

4java (http://www.4java.ca/) offers Tomcat and JBoss hosting, one JVM running by customer account starting from the second hosting solution. I've got few echoes from them, and it seems to run well.

Bill de hra
(April 21, 2004 11:50 PM #)

Damien,

yeah, a friend of my is using java from an Irish based hosting service. I'm going to get him to ask them how they deal with multiple users.

Trackback Pings

TrackBack URL for this entry:
http://www.dehora.net/mt/mt-tb.cgi/1248

Listed below are links to weblogs that reference The reason PHP is more popular than Java: it's safer:

» Java vs. PHP it is about abstractions from Radovan Janecek: Nothing Impersonal
I agree with Bill's post fully. I would just add more general observation. Java (platform, not a language) defines too many abstractions that are very difficult to handl by an operating system. It's all about server-side component models (corba, ejbs, ... [Read More]

Tracked on April 20, 2004 09:12 PM