0

I have read many articles saying this, Since java directly runs bytecode and for PHP its loaded and complied on every request, so PHP is slower as compared to Java

But what if we use a cache system for PHP like APC or EAccelerator, do the results of both Java and PHP in terms of performance near?

Akash
  • 4,956
  • 11
  • 42
  • 70

2 Answers2

1

Do not read such articles... It's impossible to compare two different languages and say it's slower because it's not compiled. Yes, parsing PHP code takes time, but JVM requires additional resources, too.

APC or EAccelerator may increase performance but it doesn't mean it will be as fast as Java or C.

meze
  • 14,975
  • 4
  • 47
  • 52
  • 1
    One thing that in general gives java an advantage over php is JIT compiling. There are some on the fly optimizations that can occur based on patterns of use that php doesn't have an accepted answer for. – Mike Lively Jul 13 '12 at 20:18
1

Frankly, few developers are writing performant enough code for this to matter. A good PHP programmer will write faster apps than an average Java programmer, and vice versa. And if you're not a good programmer, it won't matter, you'll make them both slow.

Don't get me wrong, you should certainly use an opcode cache for PHP. But if you are, the difference in performance between Java and PHP is unlikely to be the determining factor in your app's performance.

Java has threading and persistence, so if those are important use Java. PHP is super easy to deploy, and does not require extensive tuning of things like heap & garbage collection, so if that's important to you, use PHP.

Unless you're a decent sized website, use the one you know best. You'll have written it twice and optimized it before you write it once in the other language.

DougW
  • 28,776
  • 18
  • 79
  • 107