Home >Backend Development >PHP Problem >How to implement php cluster

How to implement php cluster

(*-*)浩
(*-*)浩Original
2019-10-18 10:56:537618browse

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.

How to implement php cluster

#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!

Statement:
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