How we translated the server to php 7

    php 7 was released almost a year ago, version 7.1 is already on the nose, which is in the release stage of the candidate. The Internet is full of positive reviews, so it's time to use it in production. The experience of moving a battle server with thirty projects to it will be discussed in this article.

    The seventh version opens up many new opportunities for us, but the main killer innovation of php7, I believe, is to increase performance and reduce memory consumption. In internal projects, we tried it for a long time, made sure that it gives growth not only in synthetic tests, it was decided to transfer the entire production to it.

    Server and projects

    Our production server is a server from HP with a quad-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 traffic of about 1-2 thousand unique visitors per day. All projects are written on the yii framework 1.1 of different versions, ranging from the 14th to the 17th. Everything works on a bunch of nginx-php-fpm.

    We started a move not from a good life. The server was a little tricky to cope with requests, and during peak hours of work, a robot from some immodest search engine or a parser from some schoolchildren arrived and delivered a noticeable amount of problems.

    How did you go

    They decided that we can’t switch everything at once, we need to translate one or two projects. We raised the second version of the php-fpm daemon for the seven. For the site for which the move was planned, a second separate socket was raised. Next, the socket was changed in the nginx configuration. This allowed us, in case of any problems, to quickly change the socket back and return the site to a usable state with one service nginx reload command.

    What happened to the server

    On day x, a victim was selected, 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 in 400-500 ms. instead of 600-800 ms. Here is a picture of the time the first page of the first victim returned. We pay attention to the beginning of September.


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

    After the translation of two or three projects, the overall picture on the server began to change. Each subsequent move unloaded him even more. This picture shows the dynamics over the past four weeks.


    It became easier for the server, it was evident even on those sites that were the last in the queue and worked on php 5.6 until the last moment (we look at September and October)


    And now we have reached this state, October and November on the chart does not need comments.


    The load on the disk subsystem has also fallen


    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, there was only one. It is connected with the fact that php allows you to shoot your leg, then the second leg, and even the hand that you shoot.

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

    Of the interesting. One of the sites did not start immediately, it turned out that there was a method in its code in which two input parameters had the same name. 5.6 worked quietly and buggy, and 7.0. cursed and fell.

    Well, not without gouging. Two sites worked on one socket, for the first they changed the name of the socket, no one remembered the second site and it wasn’t monitored, as a result, he spent the whole night until the marketers saw the metric errors the next day and ran.

    In the end

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

    Also popular now: