⬆️ ⬇️

How we translated server to php 7

php 7 was released almost a year ago, version 7.1 is already on the nose, which is currently being released. The Internet is full of positive reviews, but it’s time to use it in production. The experience of moving a combat server with thirty projects to it will be discussed in this article.



The seventh version offers us many new features, but the main killer innovation php7, I believe, is an increase in performance and a decrease in memory consumption. We tried it for a long time in internal projects, we made sure that it gives an increase not only in synthetic tests, it was decided to transfer all production to it.



Server and projects



Our production server is a HP server with a four-core Xeon X3430 processor at 2.40GHz and 16GB of RAM. About 30 sites are hosted on the server, about half of them are medium-sized online stores, for 10-20 thousand products with an attendance of about 1-2 thousand unique visitors per day. All projects are written on yii framework 1.1 of different versions, ranging from the 14th and up to 17. Everything works on a bunch of nginx-php-fpm.



We did not move from a good life. The server was tough to cope with requests and, during peak hours, the incoming robot of some indiscreet search engine or the parser of some schoolboy, if they did not drop the server, delivered a noticeable amount of problems.

')

How to move



We decided that we could not switch everything at once, we need to translate on one or two projects. Raised the second version of the demon php-fpm for seven. For the site for which the move was planned, a second separate socket was raised. Next, the socket was replaced in the nginx configuration. This allowed us in case of detection of any problems to quickly change the socket back and one command service nginx reload to return the site to a healthy state.



What happened to the server



On day x, the victim was chosen, which is not a pity, the configs were changed, the process began. On the site, the transition was immediately felt. Pages began to be given for 400-500 ms. instead of 600-800 ms. Here is a picture of the return time of the main page of the first victim. Pay attention to the beginning of September.



image


Unfortunately, we monitor only the main pages with nagios, they are fairly well optimized, so the growth there is noticeable, but not the maximum. The maximum is visible on heavy pages with a large number of goods, there it is even more significant, but I have no graphs.



After the translation of two or three projects, the picture in general on the server began to change. Each subsequent move unloading it even more. This picture shows the dynamics of the last four weeks.



image


It became easier for the server, it could be seen even on those sites that were the last in line and worked on php 5.6 until the last moment (we are looking at September, October)



image


And now we have arrived at this state, on the graph in October and November it does not need comments.



image


Fell on the disk subsystem



image


What were the problems



As we expected, the new version did not bring big problems (otherwise we would simply not have mastered the move)



Of the most significant was only one. It is connected with the fact that php allows you to shoot yourself a leg, then the second leg, and even the hand with which you shoot.



The seven functions of the substr function changed in the seven, one of the methods for handling the http request broke in yii, but Alexander Makarov and his colleagues corrected it a long time ago, so everything was decided by updating the framework version on these projects.



From interesting. One of the sites did not start right away, it turned out in his code there was a method in which two input parameters had the same name. 5.6 worked quietly and buggy, but 7.0. swore and fell.



Well, not without razdolbaystva. Two sites worked on one socket, for the first they changed the name of the socket, nobody remembered about the second site and it was not monitored, as a result, he lay all night until marketers saw the next day errors in the metrics and did not run.



At last



By experience, good code is easy to port to the new version of php. With half of these projects, we switched from 5.4 to 5.6 without any changes at all and the whole bundle at once. So write good code, use good frameworks and, most importantly, don't be afraid of changes - they are always for the best;)

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



All Articles