Simple parsing of PHP program running flow, parsing PHP process _php Tutorial

Source: Internet
Author: User

Simple analysis of PHP program running flow, parsing PHP process


Always wanted to understand the technology of web programming. PHP is an important language for Web programming, and the book 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 a few PHP tutorials, mostly the introduction of grammar, but did not give the answers to the previous questions. Recently patchwork to see something, and finally have some understanding of how PHP works.

HTTP protocol and PHP script triggering
HTTP is a request/response-based protocol that is the foundation of a protocol that supports web operations. The HTTP client sends 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 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, the HTML file is not affected by user behavior, and the content remains the same.

If you want to implement dynamic Web pages, you need to use PHP or JavaScript. PHP is a programming language for the server side, and JavaScript is a programming language for 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, which contains the file name of the Web page. After the server receives the request, finds the file that the filename points to, discovers that it is embedded with PHP code, invokes the PHP interpreter to process the file, and then organizes the processed results into response, which is sent to the client. PHP code can interact with the server-side database or other resources, or produce different pages depending on the user's actions.

Therefore, the trigger of the PHP script is to receive the request from the client on the server. After receiving a request, the server triggers a PHP script; 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. Two times the PHP script runs independently of each other, and the second script runs almost unaffected by the previous script run.

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

Code blocks for PHP
PHP code can be embedded in HTML files, often in the HTML file can see scattered throughout the PHP code block. I've been confused. In the same HMTL file, what is the relationship between different blocks of PHP code. Originally PHP will ignore two PHP code blocks between the HTML code.

  Test PHP Multiple Blocks  

This is HTML code.

<?php $var = 1; echo "


"; ? >

This is the HTML code too.

<?php $var + = 1; echo "


\ $var = $var

" ?>

The code has two blocks of PHP code that are separated by HTML code. The 1th PHP code block declares 1 variable $var, and the 2nd code block refers to $var, which changes its value. Using PHP to execute the above code, the resulting output is as follows.

  Test PHP Multiple Blocks  

This is HTML code.


This is the HTML code too.


$var =2

The 2nd block of code can refer to $var. Although separated by the HTML code, the execution of the two pieces of code completely ignores the HTML part. PHP output is the same as the following PHP code is not separated by HTML, the former just inserted in the PHP output of the corresponding HTML code.

  <?php    $var = 1;    echo "


"; $var + = 1; echo "


\ $var = $var

" ?>

http://www.bkjia.com/PHPjc/1136604.html www.bkjia.com true http://www.bkjia.com/PHPjc/1136604.html techarticle simple analysis of the PHP program running flow, parsing PHP process has always wanted to understand the technology of web programming. PHP is an important language for Web programming, and the book always says that PHP is used for server-side editing ...

  • 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.