socket - using php multi-threading, multi-process? ?
I. What is the usage of php multi-process? ? (used by most php programs | almost never used)
II. What is the usage of php multi-threading? ? (used by most php programs | almost never used)
III. How do php multi-process and php multi-thread compare with java? ? (simply terrible | not even close)
Almost everyone on the Internet writes that PHP is not suitable for multi-threading (is it also not suitable for multi-process??). Does this mean that there is no need to understand PHP-related features such as multi-threading and multi-process? ?
And recently, due to personal preferences, I want to make a web-based chat tool similar to QQ. Now I basically understand socket communication, but I have learned about open source communication frameworks like Workerman. His feature introduction includes the following:
I. Can PHP multi-process take advantage of multi-core CPUs, improve performance, and support high concurrency? ?
II. A single php process can support thousands or even tens of thousands of concurrent connections, and multiple processes can support hundreds of thousands or even millions of concurrent connections. How to understand this sentence? ? Since it uses sockets for communication, the number of ports is actually fixed and will not exceed 65536. One port represents a pair of connections. The thousands mentioned here -" tens of thousands may be better, multi-process Are the hundreds of thousands or millions of bets so powerful? ?
Reply content:
I. How is the usage of php multi-process? ? (used by most php programs | almost never used)
II. What is the usage of php multi-threading? ? (used by most php programs | almost never used)
III. How do php multi-process and php multi-thread compare with java? ? (simply terrible | not even close)
It is almost written on the Internet that PHP is not suitable for multi-threading (is it also not suitable for multi-process??). Does this mean that there is no need to understand PHP-related features such as multi-threading and multi-process? ?
And recently, due to personal preferences, I want to make a web chat tool similar to QQ. Now I basically understand socket communication, but I have learned about open source communication frameworks like Workerman. His feature introduction includes the following:
I. Can PHP multi-process take advantage of multi-core CPUs, improve performance, and support high concurrency? ?
II. A single php process can support thousands or even tens of thousands of concurrent connections, and multiple processes can support hundreds of thousands or even millions of concurrent connections. How to understand this sentence? ? Since it uses sockets for communication, the number of ports is actually fixed and will not exceed 65536. One port represents a pair of connections. The thousands mentioned here -" tens of thousands may be better, multi-process Are the hundreds of thousands or millions of bets so powerful? ?
Correct a concept: the total number of ports is an unsigned short, which is 65535. This does not mean that a server can only support so many connections! One port corresponds to one process, and the number of connections of a process is consistent with the number of socket descriptors
opened by this process. The number of descriptors is on the order of 32-bit int. Of course, the system has a limit on the maximum descriptors of a process, which can be configured through kernel parameters, but hundreds of thousands are definitely no problem.
The working principle of a typical multi-process http server is roughly like this: a process is responsible for monitoring the connection on port 80. When the connection arrives, the corresponding descriptor is created by the kernel, and then the process finds a relatively idle child process
To process this descriptor, that is, read and write data on this descriptor. Note that this is a child process
. It is precisely because of the child process that descriptors can be passed between parent and child processes. If the number of accesses increases and the number of child processes is insufficient, the parent process can create new child processes to handle descriptors as appropriate; the parent process should implement a simple load balancing strategy to a certain extent.
The working principle of the http server based on multi-threading is actually similar. Changing the above process
to thread
can also be explained.
The above explanation has nothing to do with PHP. PHP just encapsulates these underlying concepts and system calls. Most people use php which is based on the php script interpreter. And workerman
should be an http service implemented based on php-encapsulated system calls.
-
The php process is managed by php-fpm (implementation of fastcgi): the master process will distribute requests to child processes
-
master process: service communicates with web server
Communication implementation method 1: http socket (host + port), will occupy one port, so that means php-fpm only occupies one port here
Communication implementation method two: unix domain socket (inter-process communication), which is based on .sock file and does not rely on network protocols, so in theory it does not occupy ports
pool process: child process, including parser, parsing script
-

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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

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

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

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,

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

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

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