What is the nature of the way CGI and servlet run? What is the fundamental difference between PHP and Java in web development?

Source: Internet
Author: User

Reply content:

Now the CGI running server should be gone, PHP is fastcgi, and this agreement can continue to today's most important reason. The servlet and Python wsgi can be likened to a programming interface that allows the Web server and Web applications to be clearly delimited, and each incoming request invokes the Servlet interface, so that the Web application does not have to care about the web Server uses technical details such as multithreading or multi-process or multiplexing, and only needs to implement this interface. Since it is a programming interface, it must be related to programming language, the servlet can only be used in Java, other languages can not be programmed with the servlet (unless there is a way to do with Java compatibility)
FASTCGI is a network protocol that works on a socket and is not language-neutral. The previous CGI usually comes in each request, from the server fork out a process, just processing this request, processing completed to exit, processing is to get the HTTP header from the environment variable, read the post data from the standard input, output HTTP response from the standard output. Because of the need to constantly create and destroy processes, this implementation performance is relatively low, and features are subject to many limitations. FastCGI is an improvement of CGI, which accepts multiple successive requests on a single connection, one for processing, thus increasing throughput. FastCGI and CGI are language-independent, and any language can use fastcgi as long as it follows the FASTCGI protocol, but its processing model is limited and typically only one request can be processed at a time on a single connection, so that a certain degree of concurrency is achieved. You have to create many processes (FastCGI also have multiplexing capabilities, but don't know how to support them)

But actually from the Web application point of view, the difference between the two is not big, although PHP uses fastcgi, but also for each request to call PHP script. While many PHP programmers prefer to mix web pages and code together to make it difficult to maintain, PHP also supports using OOP in a way that uses MVC like Java, and Java also supports templates that embed code such as JSP. The difference is that Java works in the same process, can call global objects, can use an additional thread pool, and so on, while the life cycle of a PHP object is basically limited to a single request, but many things are similar and are programmed for request. Look at the difference. Start with a simple server code
CGI See Python's built-in Cgihttpserver
The main code is as follows, run_cgi,fork the process before running the CGI program, and the server process is in the parent-child relationship
the servlet looked at Spring+jetty, The servlet looked at Spring+jetty,
The app code and the server are in the same process The app code and the server are in the same process
  • 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.