Table of Contents
简单解析PHP程序的运行流程,解析php流程
Home Backend Development PHP Tutorial Simple analysis of the running process of the PHP program, analysis of the php process_PHP tutorial

Simple analysis of the running process of the PHP program, analysis of the php process_PHP tutorial

Jul 12, 2016 am 08:49 AM
php run

简单解析PHP程序的运行流程,解析php流程

一直想了解Web编程的技术。PHP是进行Web编程重要的一种语言,书上总是说,PHP是用于服务器端的编程语言。但是,实在不能理解它是怎么用于服务器端编程,如何被运行。也看过一些PHP的教程,大多是介绍语法,却没有给出前面的问题解答。最近东拼西凑的看了一些东西,终于对PHP如何运行有了一些了解。

HTTP协议与PHP脚本的触发
HTTP是一种基于Request/Response的协议,是支持Web运行的协议基础。HTTP的客户端发送Request
到服务器端,服务器端返回Response。Request中包含客户端需要访问的页面的文件名。服务器端返回该文件名指向的网页。如果没有使用PHP、JavaScript等,HTTP协议传输只能是静态的HTML文件。也就是,HTML文件不会受到用户行为的影响,内容一直保持不变。

2016623173524269.gif (411×473)

如果要实现动态网页,就需要使用PHP或JavaScript。PHP是用于服务器端的编程语言,JavaScript是多用于客户端的编程语言。

PHP代码是在服务器端被执行的。用户访问一个包含PHP代码的网页时,发送Request到服务器,其中包含网页的文件名。服务器收到Request后,找到文件名指向的文件,发现其中嵌有PHP代码,会调用PHP解释器处理该文件,然后将处理后的结果整理到Response,发送到客户端。PHP代码可以与服务器端的数据库或其他资源进行交互,或者根据用户的操作产生不同的页面。

因此,PHP脚本的触发是在服务器收到客户端的Request。收到一个Request后,服务器触发一个PHP脚本;处理完脚本后,返回结果到客户端,等待下一个Request。当收到下一个Request后,服务器触发另一个(或同一个)PHP脚本。两次PHP脚本的运行是相互独立的,第二次脚本的运行几乎不受前一次脚本运行的影响。

JavaScript代码一般是在客户端被执行的,即被浏览器所处理。客户端从服务器端获取的是JavaScript代码,而不是代码被执行后的结果,然后调用解释器执行该代码。

PHP的代码块
PHP代码是可以嵌入到HTML文件中的,经常可以在HTML文件中看到散落在各处的PHP代码块。我也一直困惑在同一个HMTL文件中,不同的PHP代码块之间是怎样的关系。原来PHP是会忽略两个PHP代码块之间HTML代码的。

<head>
  <title>Test PHP Multiple Blocks</title>
</head>
<body>
  <p>This is HTML code.</p>

  <&#63;php
    $var = 1;
    echo "<p>This is PHP code block 1. <br/> \$var=$var </p>";
  &#63;>

  <p>This is HTML code too.</p>

  <&#63;php
    $var += 1;
    echo "<p>This is PHP code block 2. <br/> \$var=$var</p>" 
  &#63;>

</body>

Copy after login

代码中有两个PHP代码块,它们被HTML代码隔开了。第1个PHP代码块声明了1个变量$var;第2个代码块引用$var,进行改变了它的值。用PHP执行上述代码,得到的输出如下。

<head>
  <title>Test PHP Multiple Blocks</title>
</head>
<body>
  <p>This is HTML code.</p>

  <p>This is PHP code block 1. <br/> $var=1 </p>
  <p>This is HTML code too.</p>

  <p>This is PHP code block 2. <br/> $var=2</p>
</body>

Copy after login

第2个代码块是可以引用$var的。虽然被HTML代码隔开了,但是两段代码的执行完全忽略了HTML部分。PHP的输出与下面没有被HTML隔开的PHP代码是一样的,前者只是在PHP输出结果之间插入了相应的HTML代码。

  <&#63;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>" 
  &#63;>
Copy after login

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1136604.htmlTechArticle简单解析PHP程序的运行流程,解析php流程 一直想了解Web编程的技术。PHP是进行Web编程重要的一种语言,书上总是说,PHP是用于服务器端的编...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles