Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I work in a PHP based company. There is a project where we want to create a backend service. Senior members here are going for PHP, even though it is slower than Java. Their only point of contention, that Java is heavier than PHP in both memory and cpu load standpoint.

Jvm is more like a container environment, if u bring in more baggage it will consume that much, but service we are talking here will be of medium complexity. So chances are that it won't be much demanding (or will it?)

I understand this question leans heavily towards vagueness, however my point of ponder is, that is it always the same case? That java is more hardware demanding? I would just like to know opinions of all you experienced folks about how the actual scenario looks like.

share|improve this question
Another good question:… – dan1111 Mar 6 '13 at 13:06
In most cases, the language/platform is not the deciding factor when it comes to speed. If you fail to properly tune a database, for example, it'll be slow regardless of the language being used. – GrandmasterB Mar 6 '13 at 18:26
I don't see why Java would take up more CPU than PHP. In most cases, I'd expect the opposite, since there will typically be less start up costs on each request. – Darius X. Mar 8 '13 at 11:24
@Shades88 Well, then, maybe you or they should try a small proof of concept: some module/part of code which they think will be very memory hungry and/or slow in Java should actually be implemented in both languages and see how it behaves. You (they) might be surprised by things such: Java's extra memory needs are actually not all that much over what the PHP version needs, Java's version might be substantially faster. – Shivan Dragon Mar 10 '13 at 15:30

If you're worried about speed, write the back-end in a compiled, fast-as-you-like language such a C or C++. There are plenty of webservice tooling to create simple C/C++ web services that you can consume from your PHP clients.

However, if you want to code it quickly and performance isn't so bad, then write it in PHP. You also have the benefit of already having the skills necessary to do this, so that's a double bonus.

Java isn't massively bloated compared to PHP, it might be a 'step up', but you'll have to learn all the niggles and tricks that you need with any new system, and I doubt the benefit will be worth it compared to just writing it in PHP straight away. In most cases, if you have the skills to do it in PHP already, that should be the first choice, choosing to do it in a different language away from your main area of expertise should be very carefully considered and only chosen if there is definite benefits over your primary system (which I don't think there will be in this case)

share|improve this answer
How about compiling PHP? – Vitalij Zadneprovskij Mar 6 '13 at 13:29
using Hiphop or Phalanger? Could work, but the CPU instruction speed is usually not as big a performance issue compared to how the language works - cache hits, memory usage and IO is more important nowadays. Either way, you do highlight that PHP is a better choice than Java for them. – gbjbaanb Mar 6 '13 at 13:33
I think that if most of them know well PHP and they don't need very high performance, then PHP is the best language for them. – Vitalij Zadneprovskij Mar 6 '13 at 14:08
I wish people would stop suggesting "compiling PHP". HipHop does not compile PHP. HipHop is a source code transformer from PHP to C++ (Which is then compiled using a C++ compiler). HipHop is a solution to choosing the wrong language for the task. – Craige Mar 6 '13 at 15:29
@Craige: actually, HipHop no longer compiles to C++, it's now a run-time JIT engine: – Joeri Sebrechts Mar 8 '13 at 10:30

Many enterprise Java shops tend to add a lot of abstractions and frameworks (such as ORMs, EJBs, spring, third-part libs, containers etc) to their systems. Sometimes these abstractions are meaningful, but often they end up adding bloat (memory, cpu) and complexity.

PHP, otoh, can be used pretty much "as-is", warts and all. But with Java you certainly need to juggle a lot more parts.

So you need to factor in those other things as well before making a decision.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.