What are the essential differences between CGI and servlet running modes? What are the fundamental differences between PHP and Java in Web development?

Source: Internet
Author: User
Php Chinese network (www.php.cn) provides the most comprehensive basic tutorial on programming technology, introducing HTML, CSS, Javascript, Python, Java, Ruby, C, PHP, basic knowledge of MySQL and other programming languages. At the same time, this site also provides a large number of online instances, through which you can better learn programming... Reply: the servers running in CGI mode should no longer exist. PHP is FastCGI and the main reason for continued use of this protocol. Servlet and Python WSGI can be analogous. it is a programming interface through which Web Server and Web applications can be clearly divided into open boundaries, each incoming request will call the Servlet interface once, so that the Web application does not need to care about technical details such as multithreading, multi-process, or multiplexing used by the Web Server, you only need to implement this interface. Since it is a programming interface, it must be related to the programming language. Servlet can only be used in Java. Other languages cannot be programmed using Servlet (unless there is a way to be compatible with Java)
FastCGI is a network protocol that works on a socket and has nothing to do with the language. In general, the previous CGI process is a process from the server fork when every request comes in. it only processes this request and exits after the processing is complete. The process is to obtain the HTTP header from the environment variable, read POST data from standard input and output HTTP response from standard output. Due to the need to constantly create and destroy processes, this implementation method has low performance and many restrictions on functions. FastCGI is an improvement of CGI. it accepts multiple consecutive requests on a single connection and processes them one by one, thus increasing the throughput. FastCGI and CGI are the same as languages. any language can use FastCGI as long as it complies with the FastCGI protocol. However, the processing model of FastCGI is restricted. Generally, only one request can be processed at a single connection, to achieve a certain degree of concurrency, you must create many processes (FastCGI also has the multiplexing function, but does not know how to support it)

However, from the perspective of Web applications, the difference between the two is not big. Although PHP uses FastCGI, it also calls a PHP script for each request. Although many PHP programmers like to mix web pages and code to make it difficult to maintain, PHP also supports the use of OOP, using MVC like Java; java also supports templates such as JSP that can embed code. There are some differences. for example, Java works in the same process, global objects can be called, and additional thread pools can be used, the lifecycle of PHP Objects is basically limited to the scope of a single Request. However, many things are similar and all are Request-oriented programming. Let's start with simple server code.
CGI: View Python's built-in CGIHTTPServer
The main code is as follows. in run_cgi, fork processes run the cgi program again, and the server process is in a parent-child relationship.
Servlet for spring + jetty, Servlet for 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.