The nginx-php process problem

Source: Internet
Author: User
Some people say that PHP single process, I understand the single process is only one file can be processed at the same time if the concurrent need to queue, PHP is more than one process single process?
If this is a single process why do the following problems occur?
1.http://segmentfault.com/q/1010000002951092
2.http://segmentfault.com/q/1010000003975704
another one of the posts that says multi-process
http://segmentfault.com/q/1010000002998618

Reply content:

Some people say that PHP single process, I understand the single process is only one file can be processed at the same time if the concurrent need to queue, PHP is more than one process single process?
If this is a single process why do the following problems occur?
1.http://segmentfault.com/q/1010000002951092
2.http://segmentfault.com/q/1010000003975704
Another one of the posts that says multi-process
http://segmentfault.com/q/1010000002998618

Take PHP-FPM, PHP-FPM is a multi-process architecture service, a worker process (subprocess) can only handle one request at a time, that is, if you only open a worker process (Pm.max_children = 1), then there are 2 requests, Then the 2 requests are processed by the process on a time-by-case basis. It is recommended that I summarize the architecture of the PHP fastcgi process Manager PHP-FPM, leveraging the isolation of the pool provided by PHP-FPM, separating compute dense and I/O intensive operations, and reducing the impact of blocking on the entire PHP application.

Another example of Linux on the 2.4 series of Apache, the default event MPM is a multi-process multi-threaded Epoll event-driven architecture, PHP needs to be compiled into a thread-safe (--ENABLE-MAINTAINER-ZTS) version, to the Apache event MPM collaboration. In this case, the Apache worker process (multiple) threads (multiple) will call PHP interpreter libphp5.so, libphp7.so processing request, for a line thread PHP interpreter, at the same time can only handle a request, this is still unchanged. In addition, the Apache Winnt MPM on Windows is also a multithreaded (but single-process) architecture, and PHP works similarly.

As for the command line PHP, if you use the swoole extension, because Swoole itself provides a multi-process multithreaded event-driven architecture, this is multithreaded. If the programmer calls the pthreads extension, it is also a multithreaded program. If the pcntl extension is called, it is a multi-process program. Otherwise, it would normally be a single-process program.

Individual PHP programs are single-process, and as you say, only one request can be processed, and other requests are queued. Because of this, server software (such as Apache, etc.), in order to ensure concurrency, will open multiple PHP processes simultaneously processing requests. FastCGI PHP-FPM also started multiple PHP processes to process requests.
In addition, in the server software, such as IIS, there is a multithreaded php mode, the method of opening threads to process requests concurrently.

Specifically, the model needs to look at which SAPI to use, such as in Apache, where multithreaded models may be used, and multi-process models may be used. And PHP-FPM is using a multi-process model.

Turn from: In-depth understanding of the PHP kernel
Chapter eighth Thread Safety» section II threads, processes and concurrency
Http://www.php-internals.com/book/?p=chapt08/08-02-thread-process-and-concurrent

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