php cluster refers to many servers processing the same work, which refers to the general hardware. For example, the main function of slb load balancing is to have multiple servers processing the same work.
#The first step in building a PHP cluster is to set up load balancing. First we need three hosts:
Nginx load: 192.166.5.111 (Recommended learning: PHP video tutorial)
PHP application 1: 192.168.5.112
PHP Application 2: 192.168.5.113
Previously, on the host where the PHP application was located, we needed to install a web server such as Nginx or apache, and then use Nginx as the load.
The communication between Nginx load and PHP application is at the application layer. Nginx load is actually equivalent to a proxy. However, things are different now.
The application of Fastcgi technology allows no need to install a web server at the PHP application layer. Now PHP5.5 version supports fpm as an internal module.
In this case, the communication between the Nginx load and the PHP application is at the transport layer, and sockets are used to communicate between the two. Of course, this requires the support of the fpm service.
The concept of a cluster is not complicated. In fact, it is multiple computers working together for the same goal. In web applications, multiple servers provide services for one site.
The first step in building a PHP cluster is to set up load balancing. First we need three hosts:
Nginx load: 192.166.5.111
PHP application 1: 192.168.5.112
PHP application 2: 192.168.5.113
Previously, on the host where the PHP application was located, we needed to install a web server such as Nginx or apache, and then use Nginx as the load.
The communication between Nginx load and PHP application is at the application layer. Nginx load is actually equivalent to a proxy. However, things are different now. The application of Fastcgi technology allows no need to install a web server at the PHP application layer.
Now PHP5.5 version supports fpm as an internal module. In this case, the communication between the Nginx load and the PHP application is at the transport layer, and sockets are used to communicate between the two. Of course, this requires the support of the fpm service.
Nginx settings
First set up Nginx (192.168.5.111) and edit the nginx.conf configuration file
http{ …… upstream onmpw_phpApps{ server 192.168.18.88:9000; server 192.168.18.191:9000; } …… Server{ listen 80; server_name load.onmpw.com ##这里是域名 root /www/onmpw …… location ~ \.php$ { root /www/onmpw ##这里是PHP应用所在目录 fastcgi_pass onmpw_phpApps; …… } } }
The above is the correct Settings made by Nginx. It only contains the key parts, and the rest is the same as the settings we usually make when using Nginx PHP as a web service.
PHP host settings
The settings here are relatively simple.
First edit the php-fpm.conf file, modify the listening IP and port, and then start the fpm service
Host 192.168.5.112
Listen = 192.168.5.112:9000 //Here The port can be set by yourself. Save and exit
# /usr/local/php/sbin/php-fpm //开启服务
Host 192.168.5.113
Listen = 192.168.5.113:9000 # /usr/local/php/sbin/php-fpm
At this point, the PHP host settings are completed. Of course, the code needs to be uploaded to each of the two hosts.
Okay, after the above settings, a basic PHP cluster has been built.
The above is the detailed content of How to implement php cluster. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

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

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
