How to Make PHP Website Run Faster
Known fact that the loading speed of pages is an essential factor for every site. Users are not willing
to wait for the response of long pages and in the worst case, they can leave your site. Search engines
lower the page rank of your site when the speed is too low; This results in fewer visitors from
search engines. And yes, as a site administrator you will feel irritation if you have to wait a long time
to manage your site, knowing that this process can be speeded up. All ways to speed up your site
are divided into two basic methods: optimization of website software and optimization of server
software/hardware.
to wait for the response of long pages and in the worst case, they can leave your site. Search engines
lower the page rank of your site when the speed is too low; This results in fewer visitors from
search engines. And yes, as a site administrator you will feel irritation if you have to wait a long time
to manage your site, knowing that this process can be speeded up. All ways to speed up your site
are divided into two basic methods: optimization of website software and optimization of server
software/hardware.
Recently, the PHP department has developed several, highly loaded, PHP-based websites and
we want to share some techniques with which we can speed up sites, developed using the following
technologies/languages/tools: MySQL Percona Server, PHP, JavaScript HTML5, Nginx, Apache,
FastCGI, APC. You can use the methods described in this article to speed up your PHP-based website
quickly and effectively, regardless of the platform (Yii, Symphony, Drupal, Joomla or any other - it doesn't matter).
we want to share some techniques with which we can speed up sites, developed using the following
technologies/languages/tools: MySQL Percona Server, PHP, JavaScript HTML5, Nginx, Apache,
FastCGI, APC. You can use the methods described in this article to speed up your PHP-based website
quickly and effectively, regardless of the platform (Yii, Symphony, Drupal, Joomla or any other - it doesn't matter).
Tips to optimize the performance of web applications
SQL requires optimization
Long processing of database queries is often the cause of the slow loading of pages. Often the reason
for this is the inaccuracy of writing searches, lack of competent indexing of tables, large and complex
requests and etc. At this stage, it is necessary to capture all requests that have executed more than
2 seconds and more often to the database have been forwarded.
for this is the inaccuracy of writing searches, lack of competent indexing of tables, large and complex
requests and etc. At this stage, it is necessary to capture all requests that have executed more than
2 seconds and more often to the database have been forwarded.
You can handle requests that are too long by using the appropriate index settings in tables and
writing less bulky requests with all recommended SQL rules.
writing less bulky requests with all recommended SQL rules.
Cached data from the system from the database is the most effective way for most repeated questions.
It works like this - if one of the visitors has sent a query to the database that is returning some data,
this info will be taken out of the cache if the same query is run on the other user. This reduces the load
on the database and increases the loading time of the page.
It works like this - if one of the visitors has sent a query to the database that is returning some data,
this info will be taken out of the cache if the same query is run on the other user. This reduces the load
on the database and increases the loading time of the page.
Decreasing image size
You can often notice elements of slide shows on the main page of websites, where you will find 5-7 images of 300 KB each.
As a result, we have somewhere around 2MB, which is downloaded from the server to the user's browser.
If the website is a store and contains more than a thousand products, and each of these products contains
2-3 images (200-300Kb) on-page, all images require full loading time, which ultimately increases the page load time.
As a result, we have somewhere around 2MB, which is downloaded from the server to the user's browser.
If the website is a store and contains more than a thousand products, and each of these products contains
2-3 images (200-300Kb) on-page, all images require full loading time, which ultimately increases the page load time.
In this case, I propose:
Save the images as much as possible in JPG instead of in PNG format. Some would say that the quality
is lost, but sometimes it is not even striking, and with a large number of photos - that gives the result.
is lost, but sometimes it is not even striking, and with a large number of photos - that gives the result.
Change the compression of the image using special programs. So reducing the image quality by 10-15%
gives a major reduction in the image and visually you don't see the difference.
gives a major reduction in the image and visually you don't see the difference.
Tip: Instead of points 1 and 2, you can check each of your website URLs with Page Speed Tools
because it reports how many bytes would be saved by optimizing the images of the page.
because it reports how many bytes would be saved by optimizing the images of the page.
It is also attainable to compress images "on the fly" when getting them from server to browser. With GZIP you can
make it easy after a site connection and perform this task very efficiently
Caching
After these procedures, it is desirable to use one of the data cache systems. This allows you to store the
received data from the server in the browser cache for some time. With this method, you cannot take
data from the server after the page has been reloaded and use cached data from your browser.
It also reduces server load and reduces page load time.
received data from the server in the browser cache for some time. With this method, you cannot take
data from the server after the page has been reloaded and use cached data from your browser.
It also reduces server load and reduces page load time.
Source code optimization
It is even one of the most important methods and perhaps one of the most labor-intensive.
Initially, correctly built system foundations provide reliability, errors, and speed of operations.
Every developer knows about it but often neglects this approach. The developers should initially use
object-oriented programming paradigms to obey Model-View-Controller and the like, as these become
truths for most modern web development software. In this early phase of software architecture,
errors in the future would entail significant labor costs.
Initially, correctly built system foundations provide reliability, errors, and speed of operations.
Every developer knows about it but often neglects this approach. The developers should initially use
object-oriented programming paradigms to obey Model-View-Controller and the like, as these become
truths for most modern web development software. In this early phase of software architecture,
errors in the future would entail significant labor costs.
Experts in PHP training in Chandigarh have extensive experience in developing fault-tolerant source
code, which is flexibly scaled and adapted to the unique needs of each customer. At the same time,
the software speed remains fast and the customer retains his ability to improve the system without having
to redevelop from scratch.
code, which is flexibly scaled and adapted to the unique needs of each customer. At the same time,
the software speed remains fast and the customer retains his ability to improve the system without having
to redevelop from scratch.
We want to name fast methods for source code optimization, which give 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 statistics or similar software that collects all visitor statistics from all your pages.
- Online chat that uses JavaScript.
- Different «share options» (share buttons: Facebook, Twitter, Linkedin, and others) that use JavaScript.
Often such JavaScript is loaded before the most important visual elements are displayed on the page and
the most important visual elements are only displayed when JavaScript has finished working. Because
JavaScript requires some time not to load significant visual content, it seems that the entire page is loading slowly.
the most important visual elements are only displayed when JavaScript has finished working. Because
JavaScript requires some time not to load significant visual content, it seems that the entire page is loading slowly.
In such cases you must use asynchronous JavaScript trays:
- The first page loads visual objects (page layouts, styles, text, images), which is about 90-95% of the total visual content on the page;
- JavaScript is only fully loaded on the "background" after the first point.
As a result, we receive a user-friendly page, because almost all content on the page is displayed without delay for the end-user
2. Correction of HTML, CSS, Javascript errors
To detect such errors, use W3C Validator online, which analyzes each site, identifies such errors and
explains what kind of error this is and how to fix it. With this method, you can quickly remove obvious
errors and in most cases, it helps to speed up the process of page loading. It also helps the search engines
to be more loyal to your website, which means that the rating of the site increases.
explains what kind of error this is and how to fix it. With this method, you can quickly remove obvious
errors and in most cases, it helps to speed up the process of page loading. It also helps the search engines
to be more loyal to your website, which means that the rating of the site increases.
3. Reduction of page elements
When you load a page with products from a certain category, similar products and images are displayed in this list.
For example, you display 20-40 goods on the pagination list, which means that the exact number of images is also loaded.
In most cases, the page visitor cannot see all 20-40 items at the same time. To view them all, he must scroll with the mouse.
It follows that the first loading of 20-40 images takes a lot of time. And the visitor is bored to wait until these 20-40 photos are loaded on the page.
For example, you display 20-40 goods on the pagination list, which means that the exact number of images is also loaded.
In most cases, the page visitor cannot see all 20-40 items at the same time. To view them all, he must scroll with the mouse.
It follows that the first loading of 20-40 images takes a lot of time. And the visitor is bored to wait until these 20-40 photos are loaded on the 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 pagination type: «<<< 1 2 .... 56 57 >>>»;
- Load 6-9 new items as far as you scroll with the mouse;
- Place a vertical arrow in the lower right corner to return to the head of the page.
and freeing up system resources for other tasks.
Comments
Post a Comment