Which language is faster for web, Java or PHP?
Speed doesn't matter
in most cases.
Processing is cheap. Code in what you're comfortable with. Writing proper code goes much further for speed then choosing a language. Solid coding conventions and design plan will also help more.
Best answer I could find
"stuff to consider:
Java web applications are compiled to bytecode. Even JSPs, which are compiled at runtime. This is an advantage over most uses of PHP, where the Zend Optimizer is not in use.
Data can be cached in a live servlet instance - no direct/easy way of doing this in PHP to my knowledge (there is only ever a single instance of a servlet/JSP in memory)
- If anybody knows how to cache data in PHP without resorting to ugly hacks, please enlighten me!
Java applications tend to be n-tiered, which generally results in a more maintainable application at a slight performance penalty. This probably sounds trollish, but honestly: even within Java itself direct use of JDBC will always be faster than going through three layers of objects to the database.
But is an n-tiered Java application able to hit the database sooner than an uncompiled, hacked-up monolithic PHP script? I don't think there's an answer to that question.
All that said, I'm working on an n-tiered MVC framework for php 5 (it's called Pure (http://www.sf.net/projects/php-pure)), so my PHP applications are generally n-tiered too. I'll worry about speed when and if it becomes an issue. For now, it's definitely not an issue."
Can't answer this question with one or the other unless you define what you want to measure the speed of.
Some things are much faster in PHP (in a native function for example), other things are much faster in Java.
The intent of each language is substantially different from the other, so if you're debating over which to use for a particular task, you should generally based the decision on that task (and how well suited each language is to it) rather than performance.
For raw performance of code written in the language (as opposed to simply calling code in the standard library), Java will probably run faster than PHP as an extremely general rule. If that matters, chances are that PHP just isn't very well suited to the task at hand.
Asides speed, I believe the performance of Java is bettern than PHP, but developing a PHP project is faster
Difficult one to answer as in theory Java should be faster: its precompiled, any trivial algorithim will run faster in java than php and there has been a vast amount of work done to optimise java from improving the code is standard libraries, to JIT compilers etc.etc.
PHP loaded and interpreted every time if your not using the Zend optimiser, objects intialised on every execution, even the most trivial string varaible is actually a complex object with many methods to support.
The problem is that in practice PHP sites seem to run faster using fewer resources.
I think this is because php developers take a more straightforward approach to design and dont get lost trying to implement exotic design patterns and implementing endless pointless abstractions.