Home Backend Development PHP Tutorial Common interview points for PHP network protocols

Common interview points for PHP network protocols

Apr 24, 2018 am 09:33 AM
php common


This article introduces the common interview points about the PHP network protocol. It has a certain reference value. Now I share it with you. Friends in need can refer to it

  <?php
/** 
* Created by PhpStorm. 
* User: weisheng
 * Date: 2018/3/15 
* Time: 15:08
 */
/* 
* 常见考察点 
* 1.http协议状态码 
* 2.OSI七层模型
* 3.http的工作特点和工作原理 
* 4.http常见协议请求/响应头和请求方法 
* 5.HTTPS协议的工作原理 * 6.常见的网络协议含义及端口 
* 
*/
/* 
* 一.http协议状态码 
* 2开头(请求成功)表示处理请求成功的状态码 
*      200(成功) 服务器已成功处理请求 
*      201(已创建)请求成功且创建了新的资源 
*      201(已接收)服务器已接受请求但尚未处理
*      203(非授权信息) 服务器已成功处理请求,单反回的信息来自另一个来源 
*      204(无内容)服务器成功处理请求,但没有返回任何内容 
*      205(重置内容)服务器成功处理请求,但没有返回任何内容 
*      206(部分内容)服务器成功处理部分GET请求 
* 
* 
* 
* 3开头(请求重定向)表示要完成请求,需要进一步操作。通常这些状态吗用来重定向 
*      300(多种选择)   针对请求,服务器可执行多种操作。服务其根据请求者(user agent)选择一项操作,或提供操作列表供请求者选择 
*      301(永久移动)   请求的网页一永久移动到新位置。服务器返回此响应(对GET或HEAD请求的响应)时,会自动将请求者转到新的位置 
*      302(临时移动)   服务器目前从不同位置的网页响应请求,但请求这应继续使用原有位置来进行以后的请求 
*      303(查看其他位置)请求者应当对不同的位置使用单独的GET请求来检索响应式,服务器返回此代码 
*      304(未修改)自从上次请求后,请求的网页未修改。服务器返回此响应时,不会返回网页内容 *      307(临时重定向)服务器目前从不同位置的网页响应请求,但请求这应继续使用原来的位置进行以后的请求(遵循浏览器标准,不会从post变成get请求) 
* 
* 
* 
* 4开头(请求错误)这些状态码表示请求可能出错,妨碍了服务器的处理
*      400(错误请求)服务器不理解请求的语法 
*      401(未授权) 请求要求身份验证。对于网络登录的网页,服务器有可能返回此响应 
*      403(禁止)服务器拒绝请求 
*      404(未找到)服务器找不到请求的网页 
* 
* 
* 
* 5开头(服务器错误)这些状态码表示服务器在尝试处理请求时发生内部错误。这些错误可能是服务器本身的错误,而不是请求出错 
*      500(服务器内部错误) 服务器遇到错误,无法完成请求 
*      501(尚未实施)   服务器不具备完成请求的功能。例如,服务器无法识别请求方法时可能会返回此代码。 
*      502(错误网关)    服务器作为网关或代理,从上游服务器收到无效响应 
*      503(服务器不可用) 服务器目前无法使用(由于超载或停机维护)。通常只是暂时状态 
*      504(网关超时)    服务器作为网关或代理,但是没有及时从上游服务器收到请求 
*      505(http版本不受支持) 服务器不支持请求中所使用的HTTP协议版本 
* 
* 
* 
*/
/* 
* OSI七层模型 
*      第一层:物理层             建立、维护、断开物理连接 
*      第二层:数据链路层          建立逻辑连接、硬件地址寻址、差错校验等功能 
*      第三层:网络层             进行逻辑地址寻址,实现不同网络之间的路径选择 
*      第四层:传输层             定义传输据的协议端口号,以及流控和差错检验(协议有:TCP UDP,数据包一旦离开网卡即进入网络传输层) 
*      第五层:会话层             建立,管理,终止会话 *      第六层:表示层             数据的表示、安全、压缩 
*      第七层:应用层             网络服务与最终用户的一个接口(协议有:HTTP FTP(文件传输 21) TFTP SMTP(简单邮件发送 25) SNMP DNS(域名解析 53) TELNET(用于远程登录 23) HTTPS POP3(接受邮件 110) DHCP) 
* 
* 
* 工作特点:基于B/S模式 通信开销小,简单快速,传输成本低    无状态 
* 
* 工作原理:客户端发送请求给服务器,创建一个TCP连接,指定端口号,默认80,连接到服务器,服务器监听浏览器请求,一旦监听到客户端请求,分析请求类型后,服务器回向客户端返回状态信息和数据内容 
* 
*/
/* 
* HTTP协议常见请求/响应头 
* 请求头: 
*      请求方式:GET POST       
Accept:客户机支持的数据类型        
Accept-Charset:客户机采用的编码        
Accept-Encoding:客户机支持的数据压缩格式        
Accept-Language:客户机的语言环境        
Host:客户机想访问的主机名        
If-Modified-Since:客户机资源的缓存时间        
Referer:客户机从哪个资源来访问服务器的(防盗链)        
User-Agent:客户机的软件环境        
Cookie:向服务器带数据
响应头:
Location:这个头配合302状态码使用,告诉客户机找谁
Server:服务器的类型
Content-Encoding:数据的压缩格式
Content-Length:回送数据的长度
Content-Type:回送数据的类型
Last-Modified:当前资源缓存时间
Refresh:隔多长时间刷新一次
Content-Disposition:以下载方式打开数据
Transfer-Encoding:数据的传送格式
Etag:缓存相关的头
Expires:资源缓存多久时间,-1或0,则是不缓存
Cache-Control:no-cache
Pragma:no-cache
常见的请求方法:
1、OPTIONS返回服务器针对特定资源所支持的HTTP请求方法,也可以利用向web服务器发送‘*’的请求来测试服务器的功能性
2、HEAD向服务器索与GET请求相一致的响应,只不过响应体将不会被返回。这一方法可以再不必传输整个响应内容的情况下,就可以获取包含在响应小消息头中的元信息。
3、GET向特定的资源发出请求。注意:GET方法不应当被用于产生“副作用”的操作中,例如在Web Application中,其中一个原因是GET可能会被网络蜘蛛等随意访问。Loadrunner中对应get请求函数:web_link和web_url
4、POST向指定资源提交数据进行处理请求(例如提交表单或者上传文件)。数据被包含在请求体中。POST请求可能会导致新的资源的建立和/或已有资源的修改。 Loadrunner中对应POST请求函数:web_submit_data,web_submit_form
5、PUT向指定资源位置上传其最新内容
6、DELETE请求服务器删除Request-URL所标识的资源
7、TRACE回显服务器收到的请求,主要用于测试或诊断
8、CONNECTHTTP/1.1协议中预留给能够将连接改为管道方式的代理服务器。
注意:
1)方法名称是区分大小写的,当某个请求所针对的资源不支持对应的请求方法的时候,服务器应当返回状态码405(Method Not Allowed);当服务器不认识或者不支持对应的请求方法时,应返回状态码501(Not Implemented)。
2)HTTP服务器至少应该实现GET和HEAD/POST方法,其他方法都是可选的,此外除上述方法,特定的HTTP服务器支持扩展自定义的方法。 
*/
/* 
* 二.常见的网络协议
网际层协议:包括:IP协议、ICMP协议、ARP协议、RARP协议。
传输层协议:TCP协议、UDP协议。
应用层协议:FTP、Telnet、SMTP、HTTP、RIP、NFS、DNS。
使用TCP协议的常见端口主要有以下几种:
(1)FTP:定义了文件传输协议,使用21端口。常说某某计算机开了FTP服务便是启动了文件传输服务。下载文件,上传主页,都要用到FTP服务。
(2)Telnet:它是一种用于远程登陆的端口,用户可以以自己的身份远程连接到计算机上,通过这种端口可以提供一种基于DOS模式下的通信服务。如以前的BBS是纯字符界面的,支持BBS的服务器将23端口打开,对外提供服务。
(3)SMTP:定义了简单邮件传送协议,现在很多邮件服务器都用的是这个协议,用于发送邮件。如常见的免费邮件服务中用的就是这个邮件服务端口,所以在电子邮件设置中常看到有这么SMTP端口设置这个栏,服务器开放的是25号端口
(4)POP3:它是和SMTP对应,POP3用于接收邮件。通常情况下,POP3协议所用的是110端口。
使用UDP协议端口常见的有:
(1)HTTP:超文本传输协议。上网浏览网页时,就得在提供网页资源的计算机上打开80号端口以提供服务。常说"WWW服务"、"Web服务器"用的就是这个端口。
(2)DNS:用于域名解析服务,这种服务在Windows NT系统中用得最多的。DNS用的是53号端口。
(3)SNMP:简单网络管理协议,使用161号端口,是用来管理网络设备的。
另外代理服务器常用以下端口:
(1). HTTP协议代理服务器常用端口号:80/8080/3128/8081/9080
(2). SOCKS代理协议服务器常用端口号:1080 
(3). FTP协议代理服务器常用端口号:21 
(4). Telnet协议代理服务器常用端口:23 
*/
Copy after login



The above is the detailed content of Common interview points for PHP network protocols. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1244
24
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,

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.

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

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.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

See all articles