HOW TO SPREAD THE LOAD IN A PHP + MYSQL WEBSITE

As the number of visitors to a website increases, so does the strain on the server. This can result in a very high load, especially if the available resources are tight and there is not enough CPU or RAM to serve all requests.

A high server load can significantly increase loading times or even make a website completely unresponsive, so it is very important to handle this issue proactively and spread the load before it becomes a real problem.

There are several methods to reduce server load, depending on the budget at your disposal, we will discuss them briefly starting with the cheapest options.

OPTIMIZE YOUR SERVER

If you can’t afford more resources, the only option is to optimize your website so that it runs best on the current server.

Start by making sure that you only run the applications that you actually need, since every unused service is just draining your CPU and memory. The same is true for plugins, such as the ones installed in WordPress.

Optimizing php is tricky and you’ll probably need help from a programmer, but there are still a few things you can try. If your website is compatible with caching solutions like opcache, memcache or redis, make sure these are activated, since they can make a huge difference.

Every new php version is faster than the previous one and uses fewer resources, so you can update php step by step as long as your site loads correctly. You can jump straight to the latest version if you use a modern CMS platform like WordPress.

Your database server should also use the newest version of MySQL or MariaDB for best performance and resource use. A diagnostic tool such as MySQLTuner can suggest some useful tweaks in your configuration files.

Another great tool is mytop, which allows you to inspect SQL queries as they run. Identify the slow ones that cause high server load and ask your programmer to investigate them.

Finally, an effective caching system can greatly decrease the load on your server and allow it to respond to more requests at the same time.

Even the caching of static files is very helpful but you can also cache dynamic pages as long as the settings are right.

There are many caching options available; every CMS has several internal options or plugins. You can also install Nginx for caching in front of Apache, or use other solutions like Redis or Varnish for this purpose.

SCALE UP

Adding more resources will definitely decrease load, if you can afford them.

This is more difficult on a physical dedicated server, you might be able to add more RAM or migrate to a larger machine but this requires downtime.

However, scaling up is easy on a VPS and every cloud or virtualization solution supports it, a simple server reboot is required. Try to increase the number of CPU cores or the amount of system memory; you can also migrate your disks to a faster storage solution like SSD, if such an upgrade is available.

MOVE TO A MULTI-SERVER ARCHITECTURE

Scaling up on a single server has its limits and spreading the load to multiple servers eventually becomes a more effective option.

You can split the resource pool into several virtual machines with specific roles, depending on the needs of your website.

Linux applications run better on dedicated machines, when they don’t share resources with other services. The most simple multi-server setup for a php + MySQL site uses two machines, one is used only as a database server while the other connects to it remotely and handles the web server and php processing.

If this setup is unable to handle the traffic, it is time to implement a more complex solution. Two or more web servers can share the load between them, in this scenario you will also need a machine that will act as a load balancer in front of them.

The load balancer can be configured with Nginx or HAProxy and its role is to distribute requests to the backend web server that can respond faster. The web servers must share the same document root, which can be achieved by exporting a NFS mount or creating a separate machine for this purpose.

This solution has many advantages: it is easily scalable by adding or removing web servers and also offers some redundancy, since the site stays online even if one of the web servers crashes.

If you have a generous budget, it is also possible to implement a fully redundant solution, with a backup load balancer (using VRRP) and two database machines in a master-master setup.

 

Optimizing server load is a difficult task and even some of the biggest websites can struggle when the traffic is very intense, for example during Black Friday.

The right configuration depends on the available resources and the specifics of your website; follow the basic steps described in this article to setup a solid initial platform.

Subscribe Now

10,000 successful online businessmen like to have our content directly delivered to their inbox. Subscribe to our newsletter!

Archive Calendar

Sat Sun Mon Tue Wed Thu Fri
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Over 20000 Satisfied Customers!

From 24/7 support that acts as your extended team to incredibly fast website performance

Zelt staff were fantastic, I had a concern with a domain and they got back to me very quickly and they helped me to resolve the issue!

author
Technician, Diageo PLC

I'm using Zelt for my portfolio since 2006. The transition was seamless, the support was immediate, and everything works perfectly.

author
Photographer, Allister Freeman

Very easy to understand & use even though I am not very technologically minded. No complications whatsoever & I wouldn't hesitate to recommend it to all.

author
Actor, A&J Artists

Zelt support team have been amazingly responsive and helpful to any of my queries, thank you so much to the Zelt have been amazingly responsive and helpful to any of my queries 👍👍👍

author
Technician, Diageo PLC

Anytime I've had a problem I can't solve, I've found Zelt to be diligent and persistent. They simply won't let an issue go until the client is happy.

author
Doctor, SmartClinics

Zelt support team have been amazingly responsive and helpful to any of my queries, thank you so much to the Zelt have been amazingly responsive and helpful to any of my queries 👍👍👍

author
Freelancer, Fiverr

24/7 World-Class Support

Ran into trouble? Contact our Customer Success team any time via live chat or email.

  • Receive professional WordPress support
  • Our specialists are available round
Get Support