Simple analysis of PHP program running Flow _php Foundation

Source: Internet
Author: User
Tags php script

Always wanted to understand the technology of web programming. PHP is a language that is important for web programming, and it always says that PHP is a programming language for the server side. However, it is impossible to understand how it is used for server-side programming and how it is run. Also read some PHP tutorials, mostly introduced grammar, but did not give the answer to the previous question. Recently a patchwork of looking at some things, and finally on how to run PHP has some understanding.

The HTTP protocol and the triggering of PHP scripts
HTTP is a request/response based protocol that is the basis of a protocol that supports web operations. HTTP clients send the request
To the server side, the server side returns response. The request contains the file name of the page that the client needs to access. The server side returns the Web page that the file name points to. If you do not use PHP, JavaScript, and so on, the HTTP protocol transfer can only be static HTML files. That is, HTML files are not affected by user behavior and content remains unchanged.

If you want to implement dynamic Web pages, you need to use PHP or JavaScript. PHP is a server-side programming language, and JavaScript is a programming language for many clients.

The PHP code is executed on the server side. When a user accesses a Web page that contains PHP code, it sends a request to the server that contains the file name of the page. When the server receives the request, finds the file that the file name points to, discovers that the PHP code is embedded, calls the PHP interpreter to process the file, and then collates the processed results to response and sends them to the client. PHP code can interact with a server-side database or other resource, or produce a different page depending on the user's actions.

Therefore, the trigger of the PHP script is the request received from the client at the server. After receiving a request, the server triggers a PHP script, and after the script is processed, the result is returned to the client, waiting for the next request. When the next request is received, the server triggers another (or the same) PHP script. The two-time PHP scripts are run independently of each other, and the second script runs almost unaffected by the previous script.

JavaScript code is typically executed on the client, which is handled by the browser. The client gets the JavaScript code from the server side, not the result of the code being executed, and then calls the interpreter to execute the code.

Code blocks for PHP
PHP code can be embedded in the HTML file, you can often see the HTML file scattered around the block of PHP code. And I've been wondering what the relationship is between the different blocks of PHP code in the same HMTL file. Originally PHP is going to ignore the HTML code between two blocks of PHP code.

 
 

There are two blocks of PHP code in the code that are separated by HTML code. The 1th PHP code block declares 1 variable $var, and the 2nd code block references $var to change its value. Using PHP to execute the above code, the output is as follows.

 
 

The 2nd block of code can refer to $var. Although it was separated by HTML code, the execution of two pieces of code completely ignored the HTML part. PHP's output is the same as the following PHP code, which is not separated by HTML, but only inserts the corresponding HTML code between the PHP output results.

  <?php
    $var = 1;
    echo "<p>this is PHP code block 1. <br/> $var = $var </p> ";

    $var + 1;
    echo "<p>this is PHP code block 2. <br/> $var = $var </p> " 
  ?>

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.