search
HomeBackend DevelopmentPHP TutorialBasic explanation of communication protocols and processes and threads in PHP

Basic explanation of communication protocols and processes and threads in PHP

Aug 14, 2018 pm 02:47 PM
httpphpthreadprocessletter of agreement

This article brings you a basic explanation of communication protocols, processes and threads in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

We have compiled some basic information about PHP. Please feel free to take a look.

Communication Protocol

The network communication protocol is a universal language for the network. It provides communication support for the Internet connecting different operating systems and different hardware architectures. It is a universal language for the network. language.

Application layer

Name Comments
HTTP Hypertext Transfer Protocol Hypertext Transfer Protocol, display web page
DNS Domain Name System Domain Name System
FTP File Transfer Protocol File Transfer Protocol
SFTP SSH File Transfer Protocol Secure File Transfer Protocol
SSH Secure Shell

Communication Layer

Name Comments
TCP Transmission Control Protocol Three-way handshake transmission protocol
UDP
##Network Layer

NameComments IPInternet ProtocolICMPInternet Control Message Protocol , mainly used for routing to send error reports

HTTP

HTTP is the abbreviation of Hyper Text Transfer Protocol. Its development is the result of cooperation between the World Wide Web Consortium and the Internet Engineering Task Force (IETF), which eventually released a series of RFCs. RFC 1945 defines the HTTP/1.0 version. The most famous of these is RFC 2616. RFC 2616 defines a version commonly used today - HTTP 1.1.

HTTP protocol (HyperText Transfer Protocol, Hypertext Transfer Protocol) is a transfer protocol used to transfer hypertext from the WWW server to the local browser. It can make the browser more efficient and reduce network transmission. It not only ensures that the computer transmits hypertext documents correctly and quickly, but also determines which part of the document is transmitted and which part of the content is displayed first (such as text before graphics), etc.

HTTP is an application layer protocol, consisting of requests and responses, and is a standard client-server model. HTTP is a stateless protocol.

Position in the TCP/IP protocol stack

The HTTP protocol is usually carried on top of the TCP protocol, and sometimes on top of the TLS or SSL protocol layer. At this time, it becomes our Often referred to as HTTPS. As shown in the figure below

Basic explanation of communication protocols and processes and threads in PHP

The default HTTP port number is 80 and the HTTPS port number is 443.

HTTP request response model

HTTP protocol always initiates a request from the client and the server sends back a response. See the picture below

Basic explanation of communication protocols and processes and threads in PHP

This limits the use of the HTTP protocol and cannot allow the server to push messages to the client when the client does not initiate a request. .
HTTP protocol is a stateless protocol. There is no correspondence between this request and the last request of the same client.

HTTP Request

The request message sent by the client to the server includes the following format

  • Request line (request line)

  • Request header (header)

  • It consists of four parts: blank line and request data.

Get request example

GET /562f25980001b1b106000338.jpg HTTP/1.1Host img.mukewang.comUser-Agent Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36Accept image/webp,image/*,*/*;q=0.8Referer http://www.imooc.com/Accept-Encoding gzip, deflate, sdchAccept-Language zh-CN,zh;q=0.8

POST request example

POST / HTTP1.1Host:www.wrox.comUser-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)Content-Type:application/x-www-form-urlencodedContent-Length:40Connection: Keep-Alivename=Professional%20Ajax&publisher=Wiley

Part 1: Request line, the first line shows the request type, and http1.1 version .
Part 2: Request header, line 2 to line 6.
The third part: blank line, the blank line of the seventh line.
Part 4: Request data, line 8.

HTTP Response

Under normal circumstances, the server will return an HTTP response message after receiving and processing the request sent by the client.
HTTP response also consists of four parts

  • Status line

  • Message header

  • Empty line and response body.

HTTP/1.1 200 OKDate: Fri, 22 May 2009 06:07:21 GMTContent-Type: text/html; charset=UTF-8<!--body goes here-->

The first part of the status line: consists of three parts: HTTP protocol version number, status code, and status message.
The second part of the message header: used to describe some additional information to be used by the client
The third part of the blank line: the blank line after the message header is required
The fourth part of the response text: The server returns to Client text message.

HTTP status code

The status code consists of three digits. The first number defines the response category, which is divided into five categories

##1xxIndication information--Indicates that the request has been received and continues to be processed2xxSuccess--Indicates that the request has been successfully received, understood, and accepted3xxRedirect- - Further operations must be performed to complete the request4xxClient error--The request has a syntax error or the request cannot be fulfilled5xxServer-side error--The server failed to fulfill a legal request

Processes and Threads

The concept of process is the basis of the structure of the operating system. The designers of Multics first used this technical term in the 1960s, and it is more general than homework. Regarding the definition of process, it is as follows

  • An executing program.

  • An instance of a program running on a computer.

  • An entity that can be assigned to and executed by a processor.

  • A unit of activity described by a single sequential thread of execution, a current state, and a set of related system resources.

Why is the process designed?

It is very difficult to design a system software that can coordinate various different activities.

There are many jobs running at any time, and each job includes many steps that require execution in sequence, so it is not possible to analyze the sequence combination of time. In the absence of a system-level method for coordinating and cooperating across all activities, programmers are left to adopt their own ad hoc methods based on their understanding of the environment controlled by the operating system. However, this method is very fragile, especially to small errors in programming, because these errors only appear when rare time series occurrences occur.

Diagnosis can be difficult because of the need to distinguish these errors from application software errors and hardware errors. Detecting errors in a timely manner is also difficult to determine the cause because it is difficult to identify the precise scenario in which the error occurred. Generally speaking, the 4 main reasons for this type of error are as follows:

  • Incorrect synchronization

  • Failed mutual exclusion.

  • Uncertain program operation

  • Deadlock

A system is required to solve these problems Level methods monitor the execution of different programs in the processor. The concept of process provides the basis for this.

So the process can be seen as consisting of three parts

  • A program that can be executed

  • What the program needs Related data

  • Execution context of the program

Creation of the process

Traditionally, the way the operating system creates processes has a negative impact on the user and applications are transparent, which is also common in contemporary operating systems. But it would be useful to allow one process to trigger the creation of another process.

For example, a program process can spawn another process to accept data generated by the application and organize the data into a format suitable for later analysis. New processes run in parallel with the application and are activated when new data is available.

This scheme is very useful for structuring applications, for example, a server process (such as a print server, file server) can spawn a new process for each request it handles. When the operating system spawns a new process in response to an explicit request from another process, this action is called process forking.

When a process forks another process, the former one is called the parent process, and the spawned process is called the child process. In a typical situation, related processes require communication and cooperation between agents. For programmers, collaboration is a very difficult task.

What is a thread

A thread is an execution stream of a process. A thread cannot allocate system resources. It is a part of the process and is a smaller independent running unit than the process

The relationship between processes and threads

A process is like a landlord, with land (system resources), and a thread is like a tenant (thread, executing the farming process). Each landlord (process) only needs one working tenant (thread).

Process - the smallest unit of resource allocation, relatively robust, crashes generally do not affect other processes, but switching processes consumes resources and is less efficient.

Thread - the smallest unit of program execution. There is no independent address space. If one thread dies, the entire process may die, but it saves resources and has high switching efficiency.

Common processes and threads in PHP

  • In web applications, every time we access php, we create a PHP process, and of course we will also create at least one PHP thread

  • PHP uses pcntl for multi-process programming

  • PHP uses pthreads for multi-thread programming

  • nginx has only one thread per process, and each thread can handle access from multiple clients

  • php-fpm uses a multi-process model, and each process has only one thread. Threads can only handle one client access

  • Apache may use a multi-process model or a multi-thread model, depending on which SAPI is used

Related recommendations:

Five ways to communicate between AS3 and PHP (based on HTTP protocol)_PHP tutorial

Communication between PHP and Linux processes

##Http protocol post request parameters in PHP, php protocol post request_PHP tutorial

Status Comments

The above is the detailed content of Basic explanation of communication protocols and processes and threads in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

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

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment