How PHP works and the relationship between lamp four

Source: Internet
Author: User
Tags php language php and mysql


Recently set up a server, suddenly feel how the lamp between the work, or how to connect it? Usually just write procedures, never think about their working principle, take this opportunity to market evil to fill this knowledge.

L: That is, the operating system, which is built on computer hardware based on the bottom of things, equivalent to: the concept of the country, and win or Linux is equivalent to different countries

A: Is the Web server, this server equivalent to the national leader: President, play a guiding role.

M: That's the database, the place where the data is stored, quite the bank

P: is PHP, the equivalent of subordinates, to do things people

That is, PHP is an Apache plug-in program, you must rely on the Web server to run. When the client browser triggers the event--->php program submits to the Apache server---->apache Server is PHP program according to the characteristics of PHP program, submitted to the PHP engine program--->php engine program parsing and reading the database generated corresponding page

PHP engine, like Smarty, has its own tag mode and can parse this tag to generate the original ecological PHP program

so how to optimize the site? in fact, the trigger time to generate the corresponding page process, the smaller the difference, the better the user experience, then to eradicate the above steps, we can think of the optimization method is: The client committed data size has been the number of concurrent----- are submitted to Apache server for processing---Apache assigned to PHP engine---PHP program and read database---Output

1: Optimize client data submission, but when the user reaches a certain level, this data is still very large

2: Optimize the Web server, mainly to deal with high concurrency performance

3: Optimized PHP engine program: samrty template engine is very good

4: Optimized PHP Program: mainly the aspects of database reading and PHP's own program efficiency

5: Database Optimization: Database Configuration and optimization method, to achieve the most perfect match with PHP read efficiency

6: Output optimization: Using technical Ajax technology such as JS


The working process of Php,apache and MySQL combination:

php's applications are performed through a Web server (such as IIS or Apache) and the PHP engine program explaining the execution, working process:
(1) When the user enters the file name of the PHP page to be accessed in the browser address, then enter will trigger the PHP request, and transfer the request to a Web server that supports PHP.

(2 The Web server accepts this request and makes a decision based on the suffix if it is a PHP request, the Web server pulls the PHP application that the user wants to access from the hard disk or memory and sends it to the PHP engine program.

(3 The PHP engine will scan files from the Web server and read from the background, process the data, and dynamically generate the corresponding HTML page.

(4 The PHP engine will generate an HTML page back to the Web server. The Web server then returns the HTML page to the client browser.

In short: Apache is a Web server that can parse the PHP language.

How Apache works:
The Web system is client/server-style, so there should be two parts: Server program and client program. Commonly used server programs are Apache; Common client programs are browsers (ie, Netscape, Mozilla). We can access the Web page by entering a Uniform Resource Locator address (URL) in the address bar of the browser. The most basic concept of the Web is hypertext (hypertext). It makes the text no longer a traditional page-style text, but can jump from one page position to another in the process of reading. The language used to write Web pages is called Hypertext Markup Language, or HTML. The WWW service complies with the HTTP protocol, the default TCP/IP port is 80, and the client-server communication process is summarized as follows:
(1) the client (browser) and the Web server establish a TCP connection, and after the connection is established, an access request (such as Get) is made to the Web server. According to the HTTP protocol, the request contains a series of information such as the client's IP address, browser type, and the requested URL.
(2) After the Web server receives the request, the page content requested by the client is returned to the client. If an error occurs, the error code is returned.

(3) Disconnecting from the remote Web server

How PHP Works:

As shown in the following:

The relationship between apache,php and MySQL:

Apache is a Web server, primarily a function of request and response, and is a software for publishing Web sites. In the configuration file, you can set the file root directory, the file type to be processed, and the port. Apache alone cannot handle PHP code.

PHP (PHP Application Server): Can not exist alone, need to rely on Apache. It can also be said that PHP is an extension of the Apache function module, PHP as an Apache plug-in for parsing PHP code. The parsed Dynamic Web page does not exist at this time <?php?>. PHP was launched while the Apache service was started. This means that PHP must be installed on the same server as Apache and cannot be split.

MySQL: An open-source, very popular relational database. It has nothing to do with Apache, but is only accessed when it responds to SQL operations in PHP code. It does not need to be installed on the same server as Apache and can exist separately, just by connecting PHP remotely.



LANMP Working principle:


Because Apache processing PHP back-end program is relatively handy and relative to Nginx processing PHP program is relatively stable, so PHP program suitable for Apache to handle, but Nginx is very suitable for processing the front end, which produced a new production environment Lanmp,apache processing PHP Program , nginx processing front-end;

This article from "愺 Burgundy pounding his 豩" blog, declined reprint!

How PHP works and the relationship between lamp four

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.