Table of Contents
回复内容:
Home Backend Development PHP Tutorial mysql - 探讨nginx与php-fpm是不是以多进程多线程方式运行的

mysql - 探讨nginx与php-fpm是不是以多进程多线程方式运行的

Jun 06, 2016 pm 08:48 PM
apache linux mysql nginx php

Nginx

在nginx的配置文件中可以设置开启多少个nginx进程,如下:

worker_processes 2;

同时也可以设置每个进程的最大连接数,如下:

worker_connections 1024;

Php-fpm

在php-fpm的配置文件中可以设置开启多少个php-fpm进程,如下:

pm.max_children = 5

同时也可以设置每个进程的最大连接数,如下:

pm.max_requests = 500

疑惑

从nginx配置与php-fpm配置来看,它们都可以开启多个进程,而每个进程又可以处理多个连接,

按我的理解就是:nginx与php-fpm都是以多进程多线程的方式来运行的;

不知道我这样的理解对不对?

回复内容:

Nginx

在nginx的配置文件中可以设置开启多少个nginx进程,如下:

worker_processes 2;

同时也可以设置每个进程的最大连接数,如下:

worker_connections 1024;

Php-fpm

在php-fpm的配置文件中可以设置开启多少个php-fpm进程,如下:

pm.max_children = 5

同时也可以设置每个进程的最大连接数,如下:

pm.max_requests = 500

疑惑

从nginx配置与php-fpm配置来看,它们都可以开启多个进程,而每个进程又可以处理多个连接,

按我的理解就是:nginx与php-fpm都是以多进程多线程的方式来运行的;

不知道我这样的理解对不对?

这个问题比较初级,官方文档上的资料都是很全的。

Nginx 是非阻塞IO & IO复用模型,通过操作系统提供的类似 epoll 的功能,可以在一个线程里处理多个客户端的请求。
Nginx 的进程就是线程,即每个进程里只有一个线程,但这一个线程可以服务多个客户端。

PHP-FPM 是阻塞的单线程模型,pm.max_children 指定的是最大的进程数量,pm.max_requests 指定的是每个进程处理多少个请求后重启(因为 PHP 偶尔会有内存泄漏,所以需要重启).
PHP-FPM 的每个进程也只有一个线程,但是一个进程同时只能服务一个客户端。

大多数的 Linux 程序都倾向于使用进程而不是线程,因为 Linux 下相对来说创建进程的开销比较小,而 Linux 的线程功能又不是很强大。

Statement of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1653
14
PHP Tutorial
1251
29
C# Tutorial
1224
24
Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

How does MySQL differ from Oracle? How does MySQL differ from Oracle? Apr 22, 2025 pm 05:57 PM

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

Linux Operations: Managing Files, Directories, and Permissions Linux Operations: Managing Files, Directories, and Permissions Apr 23, 2025 am 12:19 AM

In Linux, file and directory management uses ls, cd, mkdir, rm, cp, mv commands, and permission management uses chmod, chown, and chgrp commands. 1. File and directory management commands such as ls-l list detailed information, mkdir-p recursively create directories. 2. Permission management commands such as chmod755file set file permissions, chownuserfile changes file owner, and chgrpgroupfile changes file group. These commands are based on file system structure and user and group systems, and operate and control through system calls and metadata.

NGINX and Apache: Understanding the Key Differences NGINX and Apache: Understanding the Key Differences Apr 26, 2025 am 12:01 AM

NGINX and Apache each have their own advantages and disadvantages, and the choice should be based on specific needs. 1.NGINX is suitable for high concurrency scenarios because of its asynchronous non-blocking architecture. 2. Apache is suitable for low-concurrency scenarios that require complex configurations, because of its modular design.

Using Apache: Building and Hosting Websites Using Apache: Building and Hosting Websites Apr 25, 2025 am 12:07 AM

Apache is an open source web server software that is widely used in website hosting. Installation steps: 1. Install using the command line on Ubuntu; 2. The configuration file is located in /etc/apache2/apache2.conf or /etc/httpd/conf/httpd.conf. Through module extensions, Apache supports static and dynamic content hosting, optimizes performance and security.

Explain how to use sessions for user authentication. Explain how to use sessions for user authentication. Apr 26, 2025 am 12:04 AM

The session realizes user authentication through the server-side state management mechanism. 1) Session creation and generation of unique IDs, 2) IDs are passed through cookies, 3) Server stores and accesses session data through IDs, 4) User authentication and status management are realized, improving application security and user experience.

See all articles