8

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.

asked Mar 6, 2013 at 12:33
10
  • 2
    Related questions on StackOveflow: stackoverflow.com/questions/8195023/… stackoverflow.com/questions/1735492/… stackoverflow.com/questions/2482090/… stackoverflow.com/questions/231707/… Commented Mar 6, 2013 at 12:42
  • 1
    Another good question: stackoverflow.com/questions/3975691/… Commented Mar 6, 2013 at 13:06
  • 2
    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. Commented Mar 6, 2013 at 18:26
  • 2
    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. Commented Mar 8, 2013 at 11:24
  • 1
    @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. Commented Mar 10, 2013 at 15:30

2 Answers 2

10

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)

answered Mar 6, 2013 at 13:19
10
  • How about compiling PHP? Commented Mar 6, 2013 at 13:29
  • 1
    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. Commented Mar 6, 2013 at 13:33
  • 1
    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. Commented Mar 6, 2013 at 14:08
  • 1
    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. Commented Mar 6, 2013 at 15:29
  • 2
    @Craige: actually, HipHop no longer compiles to C++, it's now a run-time JIT engine: github.com/facebook/hiphop-php/wiki Commented Mar 8, 2013 at 10:30
4

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.

answered Mar 8, 2013 at 8:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.