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.
-
2Related questions on StackOveflow: stackoverflow.com/questions/8195023/… stackoverflow.com/questions/1735492/… stackoverflow.com/questions/2482090/… stackoverflow.com/questions/231707/…Vitaly Olegovitch– Vitaly Olegovitch2013年03月06日 12:42:06 +00:00Commented Mar 6, 2013 at 12:42
-
1Another good question: stackoverflow.com/questions/3975691/…user82096– user820962013年03月06日 13:06:17 +00:00Commented Mar 6, 2013 at 13:06
-
2In 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– GrandmasterB2013年03月06日 18:26:51 +00:00Commented Mar 6, 2013 at 18:26
-
2I 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.– Darius X.2013年03月08日 11:24:52 +00:00Commented 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.Shivan Dragon– Shivan Dragon2013年03月10日 15:30:38 +00:00Commented Mar 10, 2013 at 15:30
2 Answers 2
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)
-
How about compiling PHP?Vitaly Olegovitch– Vitaly Olegovitch2013年03月06日 13:29:42 +00:00Commented Mar 6, 2013 at 13:29
-
1using 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– gbjbaanb2013年03月06日 13:33:22 +00:00Commented Mar 6, 2013 at 13:33
-
1I 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.Vitaly Olegovitch– Vitaly Olegovitch2013年03月06日 14:08:17 +00:00Commented Mar 6, 2013 at 14:08
-
1I 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– Craige2013年03月06日 15:29:41 +00:00Commented 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/wikiJoeri Sebrechts– Joeri Sebrechts2013年03月08日 10:30:14 +00:00Commented Mar 8, 2013 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.