📜 ⬆️ ⬇️

Acceleration and optimization of PHP-site. What technologies should be chosen when setting up a server for PHP



This article will help answer questions from owners, developers and system administrators of PHP sites:




')
Typical problem:
At some point, the site begins to open and work too slowly. It happens that the hosting company is blocking the site for excess load or resource overspending. What to do in this situation?

Maybe the site began to use too high attendance or some resource-intensive module was installed, an attack is being made, or the site is infected with a virus. One way or another, but all of these cases have something in common and this is a problem of all sites on all hostings.

And if we talk about servers for PHP, then this problem is the way the php code is executed, exactly like other meaningful settings of the environment on the server.
Regardless of whether there is a problem in your code or not, whether you have high attendance or not, very much depends on the server settings. Whatever was said would not sound empty words and this article was written.

In this review, I will test the newly installed site on one of the most common content management engines Drupal 7.33 .

Only one component of php hosting was chosen for the test. We will test the web servers Nginx and Apache2 , modules mod_php and php-fpm , versions of php php53 and php56 , let's see how apc and opcache optimizers affect the speed of the site.


Of course, these parameters are only part of the settings on which the speed of the site depends. But we intentionally
confine ourselves to this, that would not make the review endless




Continuation of this article: Comparison of Drupal code execution speed for PHP 5.3-5.6 and 7.0. "Battle of code optimizers" apc vs xcache vs opcache




You can also read my other publications on the “Ideal” cluster.






Given:







How are we going to test?


There is a zabbix server in the local network and its tasks every minute:






Testing:



1. Nginx + php-fpm56 without opcache optimizer



By architecture - this is one of the most advanced options. By performance - the biggest disappointment.



Performance leaves much to be desired, but this option will withstand the load much better than option # 2 with Apache2. Also, this option will spend RAM much more efficiently.




2. Apache2 + mod_php53 without apc optimizer



The most typical hosting option. 90% of popular hosting providers use this option. Although php53 has not been supported by developers for a long time, there are a lot of sites on the Internet that still work on this version.



This option is not only very slow, but also quickly falls under a small load due to the lack of Apache2 workflows, or due to the lack of RAM on the server.




3. Balancing and statics via Nginx, the dynamic part of Apache2 + mod_php56 without opcache optimizer



This option was created as a solution for modern sites. It is offered by hosting providers who seek to provide the latest version of PHP. According to popular belief, this version of PHP should be faster and safer than the previous ones.



Unfortunately, not all sites can work fully with this version. Almost every new version of PHP ceases to support some of the outdated and "unsafe" functions, disrupting the operation of the "old" code.
By itself, php56 without an optimizer is rather slow, and mod_php tends to fall and occupy all the memory on the server under load.




4. Nginx + php-fpm53 without apc optimizer



Enough advanced configuration for those who do not want to have problems due to errors with the code optimizer. This uses the “compatible” version of the PHP interpreter, and the resource-intensive Apache2 is also removed from the bundle.






5. Balancing and statics through Nginx, the dynamic part of Apache2 + mod_php53 + apc



Another common variation. Many hosting companies use it, but they either use it by default, or they give the opportunity to enable the optimizer in their control panels.
Apache2 is usually left to work .htaccess-rules, such as the conversion of links and CNC.



We get a speed increase of 3.5 times, compared with the option without using an optimizer.
Apache itself (when using its own mod_php module) consumes much more resources for its work than the php-fpm version. Apache2 is prone to crash if one of its modules crashes or fills up all of the server’s RAM.




6. Nginx + php-fpm53 + apc



A great option for sites on old engines that do not require complex .htaccess



I use this option when it is necessary to raise an outdated site, to achieve satisfactory speed and reliable operation from it at high loads.




7. Balancing and statics through Nginx, the dynamic part of Apache2 + php-fpm53 + apc



Option for obsolete sites with complex .htaccess. For example, old Bitrix installations.



This is ideal for legacy sites. This configuration is resistant to high loads, compatible and sufficiently productive.
Great for needing .htaccess rules and Apache2 add-ons.
Among the shortcomings - an outdated and not updated version of php, but if there is no choice - this is the best option. Great for the old versions of Bitrix, Joomla and other common CMS is not the most recent versions.




8. Balancing and statics through Nginx, the dynamic part of Apache2 + mod_php56 + opcache



Sufficiently productive, but resource-intensive configuration with all the drawbacks of mod_php.



Fast enough, but under load, the server may run out of memory, and the speed drops significantly.




9. Nginx + php-fpm56 + opcache



The most productive option.



This is the best option for all modern sites. Well holds the load, shows the best result in terms of performance. This is the option I use when the task is to optimize the performance of the site and increase its speed.
The only drawback is that we will not be able to use .htaccess and all mod_rewrite rules need to be rewritten to Nginx syntax.
Also Apache2 modules will not work. If used, this option will not work.




10. Balancing and static through Nginx, the dynamic part of Apache2 + php-fpm56 + opcache



The best option for sites where you need .htaccess. Ideal for fresh versions of Bitrix.



Well holds the load due to php-fpm. I actively use this option for most sites.




Test page home page
Configuration numberArchitectureAverage download speed kb.Average ms response.
oneNginx + php-fpm56 without opcache optimizer77.04103.6
2Apache2 + mod_php53 without apc optimizer78.79103.98
3Apache2 + mod_php56 without opcache optimizer78.85102.38
fourNginx + php-fpm53 without apc optimizer81.5597.88
fiveApache2 + mod_php53 + apc303.3729.36
6Nginx + php-fpm53 + apc312.3324.73
7Apache2 + php-fpm53 + apc339.6323,32
eight.Apache2 + mod_php56 + opcache484.9616.91
9.Nginx + php-fpm56 + opcache546.3414.08
ten.Apache2 + php-fpm56 + opcache571.1413.78
Authorization in the admin test site
Configuration numberArchitectureAverage download speed kb.Average ms response.
oneNginx + php-fpm56 without opcache optimizer67.51239.01
2Apache2 + mod_php53 without apc optimizer64.61257.51
3Apache2 + mod_php56 without opcache optimizer66.75242.42
fourNginx + php-fpm53 without apc optimizer68.79233.15
fiveApache2 + mod_php53 + apc173.8194.26
6Nginx + php-fpm53 + apc173.391.3
7Apache2 + php-fpm53 + apc182.190.5
eight.Apache2 + mod_php56 + opcache218.3577.55
9.Nginx + php-fpm56 + opcache252.8362.25
ten.Apache2 + php-fpm56 + opcache262.860.85
Logout from the test site admin
Configuration numberArchitectureAverage download speed kb.Average ms response.
oneNginx + php-fpm56 without opcache optimizer41.01184.49
2Apache2 + mod_php53 without apc optimizer42.42188.97
3Apache2 + mod_php56 without opcache optimizer42.06188.37
fourNginx + php-fpm53 without apc optimizer45.48169.15
fiveApache2 + mod_php53 + apc190.141.87
6Nginx + php-fpm53 + apc185.9241.24
7Apache2 + php-fpm53 + apc202.7839.21
eight.Apache2 + mod_php56 + opcache315.5626.23
9.Nginx + php-fpm56 + opcache373.1920.43
ten.Apache2 + php-fpm56 + opcache381.2120,57





As a summary:








And most importantly - the speed of your site depends on the configuration of your server or hosting. Having chosen the right architecture, you can get a fivefold increase in the speed of the site.




If you have any questions, difficulties, or need advice:
My profile contacts

Source: https://habr.com/ru/post/264487/


All Articles