Horizontal scaling of PHP applications

Source: Internet
Author: User
Original English text: HorizontalScalingofPHPApps combines the original text with your own understanding to make it easy to understand and view later. How can we deal with the challenges of traffic growth and other performance bottlenecks for a web website? Two aspects: optimization and expansion. Optimize php versions, such as upgrading to the latest version, database indexing, and static

Original article: Horizontal Scaling of PHP Apps combines the original article with your own understanding to facilitate understanding and future reference. How can we deal with the challenges of traffic growth and other performance bottlenecks for a web website? Two aspects: optimization and expansion. Optimize php versions, such as upgrading to the latest version, database indexing, and static

Horizontal Scaling of PHP Apps


Combine the original text with your own understanding to make it easier to understand and view it later.


How can we deal with the challenges of traffic growth and other performance bottlenecks for a web website? Two aspects-Optimization and Expansion.


Optimization, such as upgrading php to the latest version, database indexing, and static content caching, is like using Nginx for reverse proxy. For details, refer to here. Scaling includes horizontal scaling and Vertical Scaling. Vertical Scaling is simply a hardware upgrade to achieve better performance. Horizontal scaling uses more servers for load balancing to improve website performance. There are two major aspects of Server Load balancer: software and hardware. The software can be implemented using Nginx and Squid. See this list for hardware.


Horizontal scaling: multiple servers achieve load balancing. One of the important problems is data sharing between servers. For example, how to share Session data between different servers in PHP?


One way is to usePersistent load balancerThe so-called Persistent load balancer means that the Server load balancer will remember the previous request of a user, and the next request will be routed to the same server, so that Session data will not be lost. But the problem is what if the server crashes? The result is that the user's Session data will be lost. In addition, this will increase the load balancer pressure, because in addition to routing, it also requires additional memory work, which will form a new bottleneck.


Another way isShare local data. Although this method requires changes to the application, there is no performance bottleneck, and the fault tolerance is relatively good, the failure of one server will not affect other servers. In PHP, We can customize methods to process sessions. For details, refer to PHP sessions.


We can useDatabaseTo save all Session data. The database is placed on a separate server. One drawback of this is that a single point of failure (spof) will be formed, and the database will be suspended if it fails. When we use traditional Mysql, Postgre, or similar databases, all servers connect to the same database and perform read/write operations at the same time, resulting in excessive load, which leads to new bottlenecks.


You can also useShared File SystemTo share local data. However, similar to databases, there will also be single point of failure (spof), and the speed is very slow. We do not recommend this method. However, its implementation is simple and only needs to be changed.Php. iniIn the configuration fileSession. save_pathYou can. If you want to try it, we recommend GlusterFS.


Currently, many implementation methods are used:Memcached. Save the shared data in the memory. The following configuration can be made in php:



session.save_handler = memcachesession.save_path = "tcp://path.to.memcached.server:port"


In addition, the developing Redis Cluster is also a good solution. There are also implementation solutions such as ZSCM, Scache, Cassandra, and Couchbase for your reference.

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.