That being said, for your question whether PHP is always faster than Java, the answer is depends. Any comparison between two different languages will probably have this answer.
Note that your simple test leaves out many things that can directly interfere with the outcome. The fact that you have compared a web application (php running on Apache) with a "standalone" program (Java running directly over jre) and with a C program (compiled, and therefore "naturally" faster). You would have to at least be comparing JSP running on Tomcat (which is the web face of Java) with PHP to have a test that starts "roughly equivalent".
And that’s just the beginning, but I’m not going to dwell on the problems with your testing method. Remember that all these languages apply optimizations that can make a lot of difference in certain scenarios.
I’m going to focus on your question of which language is most appropriate, and the answer again is: it depends. I’ll assume we’re talking about web applications (php, jsp, apache, Tomcat).
The question is, why do you need a system that answers so quickly? Why is speed the most important factor for you, to the detriment of safety, reliability, robustness, ease of maintenance? A large portion of web applications and websites (99% percent I would say, but I have no respect reference) do not need to respond quickly as desktop applications respond, even more if we consider the variation in the quality and speed of networks (Broadband, 3G, Fiber).
If you have equivalent knowledge of Java and PHP, then I simply suggest you use both. Nothing prevents you from working with two different languages, especially if you’re a freelancer. By the time you do the project analysis, you can already decide, based on the scope, what you will use. The good thing is that you will always be "training" each one of them, which can be useful when some project or vacancy requires any of them in specific.
The biggest one, however, as far as I know, is a higher consumption of processing and memory in the case of Java (especially if it is web), which makes Java hosting more expensive, but otherwise I would say that both are equivalent in resources and capacity (considering, of course, the differences in syntax, structure and deployment).
Finally, choose the one that feels best (or both) and be happy. And, when you want, change.
This type of question is not accepted by the community. Read Gorilla vs. Shark
– user7261
There is no way to compare the two languages without specifying a specific problem. So in addition to being outside the scope as said @Andrey is based on opinions and too broad your question.
– Jorge B.
@Andrey I apologize and thank you for the "touch". I signaled pro moderator delete.
– anon
No problem. = ) Now that she has an answer, I don’t know if it is possible to delete it. Your question will probably just be closed.
– user7261
I confess that I voted in favour of the question Gorilla vs. Shark, and the title of this question here referred me to that question almost instantaneously. But when reading the contents of this one I wonder if it is not possible to accept it. What is so bizarre about it that we should close it? What’s her big difference to that: What C++ can do that C# can’t?, for example?
– Math
@Math opens meta discussion on the question.
– Jorge B.
@Math this kind of question needs to be very well asked to not attract opinions. You need to have a very clear focus, give a defined parameter of what you are looking for. Advantages and disadvantages in general, without any context is exactly the reason to fall into the Gorilla X Shark. It is possible to ask the question in a way that it can be useful, the AP needs to strive to make clear what it accurate. And why is it so important to be very clear on this? Precisely so as not to give room for useless answers, to avoid opinions rather than facts. It’s not the kind of question, it’s her way.
– Maniero
The question you mentioned What C++ can do that C# can’t?, is a very specific question and is not a comparison of which is the best. This question by title and content wants to know which language to choose, which one is better or worse. What happens, as you can see in the answer below is "depends", it turns out to be too broad and based on opinions and so on and seeing Gorilla vs Shark is also outside the scope.
– Jorge B.
"large social network" and an "ERP" are too broad terms, if you do not know how to weigh what is best between Java and PHP, I am sure you are not planning to build either of the short term, I suggest you start with something really close to your reality. What, you’re really trying to do?
– Math
@bigown So yes :) That is, if the AP can ask something that does not attract opinions it can know the difference between the two languages, in a specific way.
– Math
@Math I’m doing this discussion. But it’s more important to know that PHP is not as effective as Java. In what kind of situation I should think about migrating language.
– anon
@According to the dictionary, effectiveness means: "Achieve the planned results. Achieve the goals, achieve the goal." That is, the two can be effective, depending on what your goal is. As for "when to migrate from language", I think it can be considered too broad, at least I don’t know if I could answer satisfactorily. I think your question is salvable, but I still can’t tell you how to ask in a way that is objective and therefore acceptable by the community, probably because I still don’t understand where you’re going.
– Math
Allan, I think there’s still a lot more information missing so your question can be reopened. Like this Math, the examples you gave are very vague and generic (you said yourself "let’s say..."). Well, you said you already use PHP. And in Java, do you know how to program? If you don’t know and have a problem undeserved To solve, you don’t even have to think: use PHP. Then study Java calmly, and you will begin to notice the difference between the languages, and the limitations of each one.
– bfavaretto
Now would be good ?
– anon