How to Make PHP Websites Run Faster

Known fact that page loading speed is an essential factor for any site. Users are not willing to wait for long pages response and in the worst cases they can leave your site. Search Engines reduce page rank of your site when the speed is too slow; this results in fewer visitors from Search Engines. And, yes, as the site administrator you’ll feel irritation, if you have to wait a long time while managing your site, knowing that this process can be accelerated. All the ways to speed up your site are divided into two basic methods: website software optimization and server software/hardware optimization.
Mar 09, 2017

PHP Development

Recently Belitsoft PHP department developed several highly loaded PHP based websites and we want to share some techniques that allowed us to speed up sites, developed using the following languages/technologies/tools: PHP, MySQL Percona Server, JavaScript HTML5, CSS3, Apache, Nginx, FastCGI, APC. Using the outlined methods in this article, you’ll be able to speed up your PHP-based website quickly and effectively regardless of its platform (Yii, Symphony, Drupal, Joomla or any other – it doesn’t matter).

TIPS TO OPTIMIZE WEB APPLICATION PERFORMANCE

# SQL REQUESTS OPTIMIZATION

Long processing of database queries is often the cause of slow pages loading. Often the reason for this is incorrectness of queries writing, lack of competent tables indexing, bulky and too complex requests and etc. At this stage it is necessary to catch all requests that carried out more than 2 seconds and directed to database more often.

You can handle with too long requests by using correct index settings in tables and writing less bulky requests with all recommended SQL rules.

System caching data received from the database is the most effective way for most repeated queries. It works as follows - if one of the visitors sent the query to database which returns some data then this info will be taken from the cache if the same query will be done even from the other user. Thereby the load on the database is decreasing and the page load time increases.

# DECREASING IMAGE SIZE

You can often notice slideshow elements on the main page of websites, where you find 5-7 images, 300KB each. As a result, we got somewhere around 2MB, which are downloaded from the server to user's browser. Also, if the website is a shop and contains more than a thousand of products, and each of these products has 2-3 pictures (200-300Kb) on page, then all of the images need full load time, which ultimately increases pages load time.

IN THIS CASE I PROPOSE:

  • As far as possible, keep the pictures in JPG, instead of PNG format. Some would say that quality will be lost, but sometimes it is not even eye noticeable, and with a large number of pictures - that gives the result.
  • With a help of special programs, change image compression degree. Thus reducing the image quality by 10-15% gives a weighty image size reduction and visually you cannot see the difference.

    Tip: Instead of point 1 and 2 you can check any of your website URLs with Page Speed Tools as it reports how many bytes would be saved by optimizing the page's images.

  • It is also possible to compress images "on fly" when receiving them from server to browser. GZIP allows you to make it easily after site connection and perform this task very efficiently.

# CACHING

After these procedures, it is desirable to use one of the data caching systems. This allows to store the received data from server in browser cache for some time. This method allows not taking data from server after reloaded page and using cached data from your browser. It also reduces servers’ load and reduces page load time.

# SOURCE CODE OPTIMIZATION

In fact, it is one of the most important methods and maybe one of the most labor-intensive. Initially correctly built system foundation gives reliability, faultiness and speed of operations. Every developer knows about it, but often neglects this approach. The developers should initially use object-oriented programming paradigm to obey Model-View-Controller and etc., since it becomes truisms for most modern web-development software. In this early stage of software architecture any errors would entail substantial labor costs in future.

Experts in Belitsoft Company have broad experience in developing fault-tolerant source code, which flexibly scaled and modified for the unique requirements of any customer. At the same time, software speed remains fast and customer retains its ability to improve the system without system redeveloping from scratch.

We want to mention fast methods of source code optimization, which gives the results in a short period of time:

1. ASYNCHRONOUS JAVASCRIPT LOADING

This method is used when you have on page:

  • Yandex and / or Google metrics or similar software that collects all visitor statistics from all of your pages.
  • Online chat that uses JavaScript.
  • Various «share options» (share buttons: Facebook, Twitter, Linkedin and others) that uses JavaScript.

Often, such JavaScript is loaded before the main visual elements on page and main visual elements are not showing till JavaScript finishes its work. Since JavaScript takes some time to load not a significant visual content, it might seem that whole page is loading slowly.

IN SUCH CASES YOU NEED TO USE ASYNCHRONOUS JAVASCRIPT LOADING:

  • At first, page is loading visual objects (page layouts, styles, text, images), which is about 90-95% of total visual content on page;
  • JavaScript is fully loaded in the "background” only after the first point.

As a result, we receive a user-friendly page as almost all content on the page will be shown without delay for the end user.

2.  CORRECTION OF HTML, CSS, JAVASCRIPT ERRORS

In order to detect such errors use online W3C-Validator, which analyzes any site, indicates such errors and explains what kind of mistake is this and how to fix it. This method allows you quickly remove obvious errors and thus in most cases it helps to speed up the process of page loading. It also helps search engines to be more loyal to your website, which means the increase of site rating.

3. REDUCTION OF PAGE ELEMENTS

If you load a page with a certain category products, then similar products and images will be displayed in this list. For example, you display 20-40 goods on pagination list, which means that the exact numbers of images are loading too. In most cases, page visitor cannot see all of the 20-40 items at the same time. To view them all, he needs to use the mouse scrolling. It follows that the initial loading of 20-40 images takes a lot of time. And the visitor is bored to wait until these 20-40 pictures will be loaded on page.

POSSIBLE SOLUTIONS:

  • Load 6-12 elements for each category. In most cases, this is the exact number of elements on a page;
  • Remove the following type of pagination: «<<< 1 2 .... 56 57 >>>»;
  • Load 6-9 new items as far as you scrolling the mouse;
  • Put a vertical arrow to the lower right corner in order to return to the head of page.

As a result, this method allows you to download partly data on page, according to users’ needs, reducing the load on server and free up system resources to use on other tasks.

TIPS TO OPTIMIZE SERVER SOFTWARE/HARDWARE PERFORMANCE

# NGINX WEB SERVER INSTALLATION INSTEAD / OR IN PARALLEL WITH THE APACHE WEB SERVER

This gives enormous increase of performance, which helps to reduce the time for inquiry process more effectively. With simultaneous use of Nginx and Apache, it is possible to divide the load between two systems.

# PERCONA SERVER INSTALLATION

Percona Server is a replacement for standard MySQL. Percona stands out for improved performance and scalability. Advanced functionality allows you to gather various statistics, analyze the problems and find optimal solutions. Percona is free; it also allows accelerating the inquiry process in database for a short period of time, thereby to reduce page load time.

# FASTCGI INSTALLATION

Configure this interface on the side of the server increases the speed of the executable scripts.

# APC INSTALLATION

After installation it allows to cache executable PHP scripts, which also reduces load on web server and decrease page load time.

# OPTIMIZATION OF SYSTEM LOGS

There is a history log created on server after all system manipulations and if someone is making changes to the system. This history is accumulated in logs: FTP logs, MySQL logs, web server logs, SMTP server logs and etc. In fact, any software installed on the server can create a list of such logs. But all of these logs are extremely important, as in case of any system failures or unauthorized access by third parties, system administrator will always be able to understand causes and recover system. Logs constantly reduce servers’ disk space that could lead to unpredictable expenses on additional free disk space.

Also server creates a special system file (paging file) that is filled during peak hours, when RAM is not enough for server to handle all requests. This system file is always reserve several GB of disk space and can be increased «on fly». So if logs "eat up" the remnants of disk space, the system file cannot increase and as a result the site is very slow, and sometimes it even freezes.

There is only one way out except buying a lot of disk space:

  • Set up continued, automatic backup of current log;
  • Backup process should be scheduled on a low load time (usually at night);
  • Periodically move backup of old logs from the current site server to another location to help not to overload disk space;
  • After that, overwrite the old logs with new one on schedule.

# TARIFF PLAN CHANGE AND SERVER UPGRADE

If you have used all of the methods above and still want to speed up site response you should update servers’ hardware:

  • Processor power, RAM increase;
  • Placement of web server, server database and file storage on different servers;
  • Master and Slave modes organization on web server side. The first mode takes the main load and sends the rest to the second one;
  • Use "cloud" storage to speed up page load when loading the heavy content (images, video, sounds, etc.) from the closest server.

All of these options (or combinations) will also have a positive impact on site responsiveness and will allow to sustain at least ten thousands visitors at the same day.

Blog writers

Subscribe to Belitsoft's Blog for Entrepreneurs

Join successful software startup founders! Get insights from growing companies like, where to get an idea, how to validate it, how to launch, and how to hire people - everything. Enter your email address below (no spam):

Email *

RECOMMENDED FOR YOU

Lead Generation Design of The Best SaaS Websites

If clothes make the man, the design makes the website. That's where potential customers start evaluating a product. The SaaS website can (and should) be an online lead-generation machine, so each component of it has to be as good as possible. As people generally remember the first and the last thing they see, having impressive header and footer can go a long way towards making your product successful. What do some of the best SaaS companies do with their websites’ headers/footers? Look at this list to get and keep in mind some ideas for custom software development while building or redesigning your SaaS website. ...

PHP 7 vs Node.js

Our team is experienced both in PHP programming and Node.js development. We have a portfolio with both PHP-based applications and Node.js-based applications as well as mixed ones. What do we take into account when considering which tool to use in custom software development? ...

The Top 10 Advantages Of Laravel for Cost-Effective Web Development

Laravel framework is very popular for custom software development. It is the Most Starred PHP Framework on Github: more than 35 000 developers from all over the world (mostly from the USA) greatly appreciate robust features of this platform. Based on data of the BuiltWith, Laravel's popular websites verticals include Business, Entertainment, Media, News, Shopping, Technology, Vehicles. Why is Laravel so popular? ...

100% Remote Million-Dollar SaaS Companies

Companies that hire remote (distributed, virtual, dispersed, or dedicated) workers and do it well seem to have a huge leg up on the competition. Let’s learn how these successful SaaS companies use global talents to increase software quality and reduce the cost of rent and office supplies: Basecamp, Buffer, Chargify, Convertkit, Ghost(pro), Groove, Hubstaff, Invision, Olark, and Zapier. As the company where you can find a remote PHP developer, we believe that you could utilize their experience and expertise to build your own full remote SaaS company. ...

SaaS Founders Who Became Rich Starting With MVP

Belitsoft has a huge experience in MVP software development for startups and prototypes for existing brands. MVP is a minimal version of the product with the minimum set of features that is enough to deploy and test the key hypothesis to solve problems of this product’ potential customers. Experts suggest that, in B2B, it’s not an MVP until you sell it. Viable means you can sell it. ...

Profitable SaaS Startup Ideas

The way to get profitable startup idea is not to try to think of startup ideas (including SaaS development). It's to look for problems, preferably problems you have yourself.  In fact, for many entrepreneurs, successful business ideas start out as solutions designed to address a challenge they face personally. Solving the problem that frustrates you may be one of the best ways of finding an idea for your startup. Look at these software developers who turned their problem into success.  ...

Get A Free Quote

Do you have a software development project to implement? We have people to work on it.
We will be glad to answer all your questions as well as estimate any project of yours.
Use the form below to describe the project and we will get in touch with you within 1 business day.

Call us:
Phone - USA
Phone - BELARUS
Skype
EMAIL US:
Contact form