Nginx-PHP process problems

Source: Internet
Author: User
Some people say that PHP is a single process. I understand that a single process can only process one file at a time. If a queue is required for concurrency, is PHP a single process of multiple processes? If it is a single process, why are the following problems? 1. segmentfault. comq1000000029510922.segm... some people say that PHP is a single process. I understand that a single process can only process one file at a time. If a queue is required for concurrency, is PHP a single process of multiple processes?
If it is a single process, why are the following problems?
1. http://segmentfault.com/q/1010000002951092
2. http://segmentfault.com/q/1010000003975704
I mentioned another post about multi-process
Http://segmentfault.com/q/1010000002998618

Reply content:

Some people say that PHP is a single process. I understand that a single process can only process one file at a time. If a queue is required for concurrency, is PHP a single process of multiple processes?
If it is a single process, why are the following problems?
1. http://segmentfault.com/q/1010000002951092
2. http://segmentfault.com/q/1010000003975704
I mentioned another post about multi-process
Http://segmentfault.com/q/1010000002998618

Take PHP-FPM for example, PHP-FPM is a multi-process Architecture Service, a working process (sub-process) can only process one request at a time, that is, if you only enable one worker process (pm. max_children = 1). When two requests are sent, the two requests are processed by the worker process in time. It is recommended to look at my summary of the PHP FastCGI Process Manager PHP-FPM architecture, using the pool Isolation provided by the PHP-FPM, separating computing intensive and I/O intensive operations to reduce the impact of blocking on the entire PHP application.

For example, for Apache 2.4 in Linux, the default event MPM is a multi-process, multi-thread epoll event-driven architecture. PHP needs to be compiled into the thread security (-- enable-maintainer-zts) version, to work with Apache event MPM. In this case, the threads (multiple) in the Apache worker process call the PHP interpreter libphp5.so and libphp7.so to process requests. For the PHP interpreter in a thread, only one request can be processed at a time, which remains unchanged. In addition, Windows Apache's winnt MPM is also a multi-threaded (but a single process) architecture, and PHP works in a similar way.

For PHP in the command line, if you use swoole extension, because swoole itself provides a multi-process, multi-thread event-driven architecture, it is multithreading. If the programmer calls the pthreads extension, it is also a multi-threaded program. If the pcntl extension is called, it is a multi-process program. Otherwise, it is a single-process program under normal circumstances.

A separate PHP program is a single process. As you said, only one request can be processed, and other requests must be queued. For this reason, server software (such as Apache) starts multiple PHP processes to process requests simultaneously to ensure concurrency. FastCGI php-fpm also starts multiple php processes to process requests.
In addition, in IIS and other server software, there is also a multi-threaded PHP mode, through the thread method to concurrently process requests.

Specifically, the model depends on which SAPI is used. For example, in Apache, the multi-threaded model or multi-process model may be used. Php-fpm uses the multi-process model.

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.