PHP and Java do site backstage, what is the difference

Source: Internet
Author: User
What's the difference between PHP and Java as a Web site?

Share to:


------Solution--------------------
Copy and paste it right now.


This is seen in several ways:
First, the operating mechanism:
Java code is compiled into bytecode, will be in the virtual machine by JIT two compile into the local code, it is said that its execution speed can be comparable with C + +, after my own testing, with Java to implement a simple Memcache protocol cache server, run under Java 1.6, Compared with the memcache itself, the same amount of data access time is about 3:2, although there is a gap, but much better than imagined. Java 1.7 has made a lot of improvements in the JIT, and performance is better than Java 1.6.
PHP is the direct interpretation of the text code execution, even if there is opcode caching technology, there is still an insurmountable performance gap. php's opcode is similar to Java's class bytecode, which is still interpreted as execution.
Second, processing concurrency:
Java takes single-process multithreading on concurrent processing, Web applications start with Web server startup, and requests from Web browsers are assigned to thread Cheng idle threads, which means that when a request arrives, the process is ready and the thread is ready, The only thing Java has to do is handle the business logic.
PHP takes a multi-process approach to concurrent processing, there is no physical Web application concept in Web server, each request is equivalent to a separate application, and the process starts as the request arrives and dies as the request ends. In the fast CGI environment, there is a process pool technology similar to the thread pool, which is very helpful for performance improvement. However, on the one hand, Web server and fast CGI communication still need to pass through the socket, a certain amount of IO loss, on the other hand process pool process is also difficult to communicate, so in concurrent processing still can not compare with Java.
Third, the database application:
Java can use database connection pooling technology to save the time lost in the database connection process.
PHP does not have this benefit because it comes from the second one above.
Java has jdbc,php on the database interface, and these two are very similar. However, Java has a lot of ORM technology frameworks (such as Hibernate) that make database operations incredibly simple, and the way PHP works determines that it is an ORM (and of course, an ORM, just how much you can tolerate the performance loss of ORM).
Four, caching technology
Java is a single process, many caches can be done directly in the Java heap, without the use of external tools, of course, there is a good caching framework, such as Ehcache, because there is no network IO, so the performance is very high.
PHP multi-process single thread determines that it can only rely on external cache servers, such as Memcache.
V. Hot deployment
Java has a weak thermal deployment capability, and it's hard to do it if you want to fix a bug.
PHP Natural Hot deployment.
Vi. Cost of development
A good Java programmer needs more knowledge, development, debugging requires a longer period of time, better Web server is also charged.
PHP is free, and Web server is free.
Vii. Security
This depends on how you define security, and if it's code-safe, Java class decompile is easy, which is pretty much the same.
Java has a security configuration mechanism to ensure that some "illegal operations" can not be implemented, which is weak PHP.
However, Java is easy because a bug causes the entire application to go down, and PHP is much safer.

In fact, Java is a lot of benefits, but only the last three can let the decision-makers take PHP and abandon Java.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.