CentrioHost Blog

Stories and News from IT Industry, Reviews & Tips | Technology Blog


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

SatSunMonTueWedThuFri
 123456
78910111213
14151617181920
21222324252627
28293031 

Over 20000 Satisfied Customers!

  • web hosting reviewer
    Valerie Quinn
    CTO, Acteon Group

    Centriohost 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! ~ . . . Read more

  • Joomla hosting reviewer
    Collin Bryan
    Photographer, Allister Freeman

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

  • dedicated server reviewer
    Harry Collett
    Actor, A&J Artists

    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. ~ . . . Read more

  • vps web hosting reviewer
    Porfirio Santos
    Technician, Diageo PLC

    Centrio support team have been amazingly responsive and helpful to any of my queries, thank you so much to the Centriohost have been amazingly responsive and helpful to any of my queries 👍👍👍 ~ . . . Read more

  • wordpress hosting plans reviewer
    Catherine Auer
    Doctor, SmartClinics

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

  • reseller hosting reviewer
    Effectivo Social
    Freelancer, Fiverr

    Recommend their shared hosting for all my SME web design clients. Their cloud or VME offerings are too great to deal with. Pricing is perfect and suitable for all users (͠≖ ͜ʖ͠≖) 👌 ~ . . . Read more

Top