How PHP works and the relationship between lamp users

Source: Internet
Author: User

Recently, when I set up a server, I suddenly felt how lamp works or how it works? I usually write programs and never think about how they work. I will take this opportunity to catch up with this knowledge.

L: the operating system, that is, the underlying thing based on computer hardware, is equivalent to the concept of country, while win or Linux is equivalent to different countries.

A: It is a Web server. This server is equivalent to a country leader: the Chairman. It plays a guiding role.

M: database, where data is stored, equivalent to a bank

P: php. It is equivalent to a subordinate who is responsible for doing things.

That is to say, PHP is a plug-in of Apache. It can only run on a Web server. When the client browser triggers an event ---> the PHP program is submitted to the Apache server ----> the Apache server determines that it is a PHP program based on the characteristics of the PHP program, submit to the PHP engine program ---> the PHP engine program parses and reads the corresponding page generated by the database

PHP engine; like smarty, it has its own tag mode and can be parsed to generate the original PHP Program

So how to optimize the website?In fact, it is the process of triggering the time to generate the corresponding page. The smaller the time difference, the better the user experience. The above steps are taken apart and we can think of the following optimization methods: the size of the data submitted by the client has been the number of concurrent requests-all submitted to the Apache server for processing-Apache allocated to the PHP engine-PHP program and read database-Output

1: optimize client data submission. However, when the user reaches a certain level, this data is still very large.

2: optimize the web server, mainly to handle high concurrency Performance

3: optimized PHP engine program: the engine of samrty template is very good.

4: optimized PHP program: mainly for database reading and PHP Program Efficiency

5. Database optimization: The Database Configuration and optimization methods can perfectly match the PHP Read efficiency.

6. output optimization: Ajax technology using JS and other technologies

PHP, Apache, and MySQL combination process:

All PHP applications are explained and executed through Web servers (such as IIS or Apache) and PHP engine programs. The working process is as follows:


(1) When you enter the name of the PHP page to be accessed in the browser address, press enter to trigger this PHP request and transmit the request to a Web server that supports PHP.


(2) The Web Server accepts this request and determines based on its suffix that if it is a PHP request, the web server extracts the PHP application to be accessed from the hard disk or memory, and send it to the PHP engine program.


(3) The PHP engine program will scan the files sent from the Web server from start to end, read data from the background, process data, and dynamically generate corresponding HTML pages based on commands.


(4) The PHP engine returns the generated HTML page 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-type, so there should be two parts: server program and client program. Common server programs are Apache, and common client programs are browsers (such as IE, Netscape, and Mozilla ). You can enter a uniform resource location address (URL) in the address bar of your browser to access the Web page. The most basic concept of web is hyper text ). It makes the text no longer a traditional book-style text, but can jump from one page location to another during reading. The language used to write web pages is called the hypertext markup language (HTML. The WWW Service complies with the HTTP protocol. The default TCP/IP Port is 80. The communication process between the client and the server is described as follows:

(1) The client (browser) establishes a TCP connection with the Web server. After the connection is established, an access request (such as get) is sent to the web server ). According to the HTTP protocol, the request contains a series of information such as the Client IP address, browser type, and request URL.

(2) After receiving the request, the web server returns the page content requested by the client to the client. If an error occurs, the error code is returned.

(3) disconnect from the remote web server

 

How PHP works:

As shown in:

Relationship between Apache, PHP, and MYSQL:

Apache is a web server mainly used for request and response. It is a software used to publish websites. In the configuration file, you can set the root directory of the file, the type of the file to be processed, and the port. Apache cannot process PHP Code separately.

PHP (PHP application server): it cannot exist independently and must rely on Apache. It can also be said that PHP is an extension of the Apache function module. As a plug-in of Apache, PHP is used to analyze PHP code. Resolved dynamic webpages do not exist at this time <? PHP?> . When the apache service is started, PHP is also started. That is to say, PHP and Apache must be installed on the same server and cannot be separated.

MySQL: a popular open-source relational database. It has nothing to do with Apache and is accessed only when responding to SQL operations in PHP code. It does not need to be installed on the same server as Apache. It can exist independently. You only need to remotely connect to Apache using PHP.

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.