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.

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 perfomance

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 perfomance

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.

Sharing is caring!

Author
Written by
Partner / Department Head
I've been leading projects in Healthcare, Financial and other domains for 14 years.
0.0
0 reviews

Rate this article

Let's Talk Business

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.

Contact form
* Maximum file size is 20MB
to top