Socket-Using PHP multi-threading, multi-process??

Source: Internet
Author: User

I. How is PHP multi-process used? (The vast majority of PHP programs are used | Almost no use.)

Ii. What is the usage of PHP multi-threading? (The vast majority of PHP programs are used | Almost no use.)

Iii. PHP Multi-process, PHP multi-line Threads compare Java how?? (It's awful | Comparable

Almost all the network is written to PHP is not suitable for multi-threaded (or not suitable for multi-process?? ), is it not necessary to understand the multi-threading, multi-process and other PHP-related features??

Then recently because of personal preferences, want to do a similar QQ web chat tool, now basically understand the socket communication, but understand the next workerman such an open source communication framework, his features include the following:

I. PHP Multi-process can play multi-core CPU advantages, improve performance, and support high concurrency??

Ii. PHP single processes can support thousands of or even tens of thousands of of concurrent connections, while multi-processes can support hundreds of thousands of or even millions of concurrent connections. How do you understand this sentence? Because it uses the way of the socket to communicate, then the number of ports is actually fixed, not more than 65536, a port represents a pair of connections, said the thousands of-"tens of thousands of may be better, a lot of process hundreds of thousands of, million, there is so bad??

Reply content:

I. How is PHP multi-process used? (The vast majority of PHP programs are used | Almost no use.)

Ii. What is the usage of PHP multi-threading? (The vast majority of PHP programs are used | Almost no use.)

Iii. PHP Multi-process, PHP multi-line Threads compare Java how?? (It's awful | Comparable

Almost all the network is written to PHP is not suitable for multi-threaded (or not suitable for multi-process?? ), is it not necessary to understand the multi-threading, multi-process and other PHP-related features??

Then recently because of personal preferences, want to do a similar QQ web chat tool, now basically understand the socket communication, but understand the next workerman such an open source communication framework, his features include the following:

I. PHP Multi-process can play multi-core CPU advantages, improve performance, and support high concurrency??

Ii. PHP single processes can support thousands of or even tens of thousands of of concurrent connections, while multi-processes can support hundreds of thousands of or even millions of concurrent connections. How do you understand this sentence? Because it uses the way of the socket to communicate, then the number of ports is actually fixed, not more than 65536, a port represents a pair of connections, said the thousands of-"tens of thousands of may be better, a lot of process hundreds of thousands of, million, there is so bad??

Correct a concept: The total number of ports is a unsigned short, which is 65535. This does not mean that a server can only support so many connections! A port corresponds to a process, and the number of connections to a process is more consistent for the amount of open the process socket描述符 . The number of descriptors is 32-bit int order, of course, the system has the limit of the maximum descriptor of the process, can be configured by kernel parameters, but the last hundreds of thousands of is certainly not a problem.

A typical multi-process HTTP server works like this: a process is responsible for listening to a 80-port connection, and when the connection arrives, the corresponding descriptor is created by the kernel, and the process takes a relatively idle 子进程 handle to the descriptor, which reads and writes data on the descriptor. Note Here is 子进程 that it is because of child processes that you can pass descriptors between parent and child processes. If the amount of traffic comes up and the number of child processes is insufficient, the parent process can create a new child process to handle the descriptor as appropriate, and the parent process should implement a simple load balancing strategy to some extent.

Multi-Threaded HTTP server works pretty much the same thing, it 进程 can be explained by changing the above 线程 .

The above is not related to PHP, PHP is only in these underlying concepts and system calls encapsulated. Most people use PHP as a PHP-based scripting interpreter. Instead, workerman it should be an HTTP service implemented based on a PHP encapsulated system call.

    • The PHP process is managed by the PHP-FPM (FASTCGI implementation): The master process distributes the request to the child process

      • Master process: Service communicates with Web server

        • Communication Implementation Method One: HTTP socket (host + port), will occupy a port, so that is to say here PHP-FPM only occupy one port

        • Communication Implementation mode two: UNIX domain socket (interprocess communication), is based on the way of. Sock files, does not rely on the network protocol, so that is theoretically not occupy the port

      • Pool process: Child process with parser, parsing script

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