
This article will help answer questions from owners, developers and system administrators of PHP sites:
- How to optimize the site and speed it up?
- How fast will the site be and can work, in accordance with the technologies on which it will be launched?
- What technologies should I use when setting up a server or VPS?
')
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:
- Centos 6.7 operating system
- Database server: MariaDB 10.21
- All sessions of sites are stored in memcache in order to remove the effect of session setup speed on the speed of the site.
- On all tests, the nginx 1.93 web server is the frontend. In the case of Apache2, Nginx acts as a balancer, as well as for the return of statics. In configurations without Apache2, the direct web server is Nginx.
- The configuration of Nginx and MariaDB contain many optimizations aimed at achieving maximum performance, but for all participants in the test these settings are the same and therefore their influence should be ignored
- The opcache and apc parameters are taken from Bitrix recommendations, as they are optimal and universal for most sites.
How are we going to test?
There is a zabbix server in the local network and its tasks every minute:
- Open the main page of the test site, wait for certain content on the page, make sure that the response from the server is code 200.
- The next step is the authorization in the admin panel of the site, this happens by sending the corresponding POST request. Verification of the text and response code on the page with the established standard. This step applies to almost all subsystems of the web server, and in many ways its speed depends on the speed of interaction with the database.
- The last step is to exit the admin panel of the site, checking the response code and the text on the exit page.
- At the end of each step, zabbix will meticulously measure and write down the rendering speed of php-code in html understandable to the browser and show us the graphs of the results
- For each subject, the values ​​will be recorded for one hour and the average values ​​for this hour will be the result.
- Testing will occur within the local network, so that the impact on the result of the speed of the Internet connection is excluded
- For convenience of perception, I show all the results in ascending order. Those. the very first result is the slowest. All configurations were rendered under a conditional number, this will allow better orientation in the results.
- The upper plots - code generation rate, the higher the value, the better. Lower graphs - server response time and the lower the value, the better.
- Testing sites live their lives, they have regular operations with databases and tasks are performed on a schedule, which is why the curve in the graphs can have ups and downs
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 number | Architecture | Average download speed kb. | Average ms response. |
one | Nginx + php-fpm56 without opcache optimizer | 77.04 | 103.6 |
2 | Apache2 + mod_php53 without apc optimizer | 78.79 | 103.98 |
3 | Apache2 + mod_php56 without opcache optimizer | 78.85 | 102.38 |
four | Nginx + php-fpm53 without apc optimizer | 81.55 | 97.88 |
five | Apache2 + mod_php53 + apc | 303.37 | 29.36 |
6 | Nginx + php-fpm53 + apc | 312.33 | 24.73 |
7 | Apache2 + php-fpm53 + apc | 339.63 | 23,32 |
eight. | Apache2 + mod_php56 + opcache | 484.96 | 16.91 |
9. | Nginx + php-fpm56 + opcache | 546.34 | 14.08 |
ten. | Apache2 + php-fpm56 + opcache | 571.14 | 13.78 |
| | | |
Authorization in the admin test site |
Configuration number | Architecture | Average download speed kb. | Average ms response. |
one | Nginx + php-fpm56 without opcache optimizer | 67.51 | 239.01 |
2 | Apache2 + mod_php53 without apc optimizer | 64.61 | 257.51 |
3 | Apache2 + mod_php56 without opcache optimizer | 66.75 | 242.42 |
four | Nginx + php-fpm53 without apc optimizer | 68.79 | 233.15 |
five | Apache2 + mod_php53 + apc | 173.81 | 94.26 |
6 | Nginx + php-fpm53 + apc | 173.3 | 91.3 |
7 | Apache2 + php-fpm53 + apc | 182.1 | 90.5 |
eight. | Apache2 + mod_php56 + opcache | 218.35 | 77.55 |
9. | Nginx + php-fpm56 + opcache | 252.83 | 62.25 |
ten. | Apache2 + php-fpm56 + opcache | 262.8 | 60.85 |
| | | |
Logout from the test site admin |
Configuration number | Architecture | Average download speed kb. | Average ms response. |
one | Nginx + php-fpm56 without opcache optimizer | 41.01 | 184.49 |
2 | Apache2 + mod_php53 without apc optimizer | 42.42 | 188.97 |
3 | Apache2 + mod_php56 without opcache optimizer | 42.06 | 188.37 |
four | Nginx + php-fpm53 without apc optimizer | 45.48 | 169.15 |
five | Apache2 + mod_php53 + apc | 190.1 | 41.87 |
6 | Nginx + php-fpm53 + apc | 185.92 | 41.24 |
7 | Apache2 + php-fpm53 + apc | 202.78 | 39.21 |
eight. | Apache2 + mod_php56 + opcache | 315.56 | 26.23 |
9. | Nginx + php-fpm56 + opcache | 373.19 | 20.43 |
ten. | Apache2 + php-fpm56 + opcache | 381.21 | 20,57 |
As a summary:
- In real life, all variants with Apache2 can be slower, since in my tests I deliberately passed on the return of Nginx static. This is done to eliminate the influence of the rate of static return on the results of measuring the speed of the PHP interpreter. One of the weakest side of Apache2 and at the same time a strong Nginx - is the rate of recoil of statics. Especially, it is noticeable at high loads. In addition, Nginx is less susceptible to the attack of "slow connections".
- mod_php very quickly takes up all available server memory and loses performance on loads
- php-fpm consumes memory much more efficiently, safer and more flexible in settings. In some cases, it is faster and without high loads.
- The test has a narrow specificity, here we saw the features of the Drupal engine, others may behave differently, but the general trend will be the same.
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