Kingsoft Zhang banquet: Application of PHP in Kingsoft game Operation

Source: Internet
Author: User
Tags php server php development environment php web server

Good afternoon, everyone. Now I want to share with you the information of PHP in Kingsoft game operations, including team development and information such as system structure, design, and operation platform. I have two main topics: Applications on Kingsoft game official website and applications on Kingsoft game Operation System Keyes. Kingsoft official website includes customer service, some questions, know, and so on, including game-related products, which mainly uses the Linux system, 64-bit, and PHP version 5.2. First of all, let's look at the collaborative development of teams. We must have encountered a situation where many of our current projects are engaged in the development of a project, and the development environment and test environment are different. We use all PHP on Windows, but many people develop code in Linux. After I change a function, I want to check the execution result immediately. In this case, the corresponding platform can be configured on Windows, however, we also develop some extensions like PHP, such as distributed image processing and some cache systems, which are for PHP extension development in Linux. Therefore, it cannot be used on Windows platforms. This is a hope to write a program that can be seen immediately, but we do not need to write a program to the server for testing, it is too slow. If the number of people on the same server develop at the same time, you may overwrite other people's programs, and there is no way to control them. We can see that we use the PC mode in the Windows development environment of programmer A. We can see from the above that, if both programmer A and programmer B develop code on Windows, we can install Nginx on Windows. We develop programs in Windows, and each programmer can perform tests. After the tests, we can perform debugging. The execution result is still executed in Linux. From this process, we can see that a programmer first obtains a project version and makes some modifications. After the modifications, he can use the same Linux testing server for debugging. After the test is complete, there is no problem in this level of test. You can submit it to my SVN version library and create an automatic synchronization program, including the Linux development and testing server. This SVN synchronization will automatically notify Linux to update the latest code. Later we found that there was a problem. If there were a lot of program files, SVN was very slow before, so that programmers could submit SVN after testing. For convenience, we need to make a prediction. We have a virtual host every day. We add a virtual host on the left. After adding the virtual host, we will implement the current directory on Linux. As shown in the following figure, you can set tosts as the local IP address. After modifying a file on your computer, you can submit the file after local debugging is complete. Compile a PHP code file in Windows and debug it with PHP in Linux to ensure a unified development environment and test environment generation environment. The entire PHP development environment and testing environment ensure that programmers can quickly modify and adjust code requirements, and that the entire code is under SVN version control. This problem occurs again in the development environment, ensuring the uniformity of PHP code. In the development environment, we first go to the offline test environment. After the offline test, we go to the online test environment, and finally to the formal environment. There are many environments. In addition, we have many development projects, including more than 10 projects. Many projects connect to MySQL, Memcached, interface IP addresses, send text messages, and query user data. Their ports are different. programmers often make mistakes, in this case, the system engineer must be the one who knows the server license the most. In this case, the two must be separated. Let's get the most familiar with this business, so we have developed a PHP extension and a kae-config Management backend. We release it on each server through a backend, all we need to do is to configure different parameters and IP Ports for different server systems in different environments. After every PHP version is unified, including PHP files, PHP code will be released online. I don't know how other companies do it. We will hand over the release to the Program Development owner of each project, which will free system engineers from code release. From release to release a version, if we want to release version 1.0, Which is version 2.1.46, it can be matched. If we want to release version 2.1.46 of the user center, it can correspond to version 21901, if there are any changes between the two versions and the previous version, we can get them through PHP. When the system is released, we can only publish this file. So we developed a code release background. We can see from the above two marked red spots that we have added a new release version with the Primary and Secondary versions. In this way, each engineer will develop a version, including a project, which can have different owners for commercial release. related information will be submitted for each launch. Click the button on the right to see which version we want to start. We can release the version. If we find that there are major problems after the version is released, if it takes a long time to solve the problem, return to the previous version immediately, and control the version through each version release, so that the entire version release is clear at a glance. Third, PHP is combined with open-source products and C/C ++ programs. Use the PHP client extension to communicate with C/C ++ open-source programs through the TCP protocol, such as search with Sphinx. Method 2: We develop some HTTP-based communication with C/C ++ open-source programs, such as HTTPQS, an open-source simple message queue software developed with our fonts. PHP Web programs require that each request be very fast, and the processing speed should be solved in milliseconds. We also encountered some services, such as sending text messages and sending emails, which took dozens of seconds, which made the user experience poor when waiting on the front-end page. We also need to upload videos. We need to convert the video format and perform data mining. We need to record some user information and some logs, so that we need to process them asynchronously. In order to solve asynchronous processing, there are two situations. One is short time-consuming asynchronous processing, which takes 1 or 2 seconds to record some digital mining information, which can consume less time, at this time we can provide the fastcgi-finish-reques function with PHP-FPM. After you call this function, the following execution result will not be waiting for the following result, so that you can implement some Asynchronization. Fastcgi-finish-reques function disadvantages. PHPFastCGI processes are limited and PHP-CGI processes that are processing asynchronous operations cannot process new requests. If the concurrent access volume is large, the php-cgi process count is full, and the new access request will not be processed by the php-cgi amount. The Nginx server appears. The 502 Bad operation is implemented in a queue, including the open source queue. In this case, in our product application, we apply some clear text messages below. We can first enter the queue and then send emails from the queue, like refreshing the cache on the previous page, benefits can be solved asynchronously by converting video pages above. We adopt a PHP server Load balancer method. From this architecture diagram, we have a rough game official website architecture. We can see that there are forums and some common PHP services. We use two servers at the frontend for balancing. The following large businesses are like forums or game activities, draw a separate set of PHP external servers. In this way, the Server Load balancer is distributed to the following PHP for voluntary processing, and some connections from PHP to the backend will be made. Just now we mentioned some operations like distributed image processing, some search engines, and these interfaces. Of course, we are developing services. Because we have multiple WEB servers, we also need to pay attention when developing PHP. In the past, in order to cache a single program recently, if it is deployed on multiple servers, it may survive on this server, but it does not survive on that server. In addition, each access generates many small files, which occupy a large amount of Linux browsing. Sometimes the disk is not complete, but there is no way to create a new file because many small cache files are created, the entire application is full. In this way, I use APC and Memcached to cache data objects. There is also the HTML output webpage cache. We use the front-end Nginx Server Load balancer to make a cache. Nginx Server Load balancer now supports caching and allows you to access dynamic content to the backend WEB server for caching. For some long-term pages, such as the official game website, some images can not only change. There is one advantage: on the WEB server, PHP files can be centrally managed, added, and deleted through the Code publishing system, which is very fast and can be centrally managed by System Engineers. In addition, code tampering prevention is involved. In case a customer uploads a Trojan, a pre-judgment can be developed in our PHP program to solve the problem. Because our PHP program is released through the code system, it can be executed. If it is not a program released by the system through our code, if it creates a PHP file on it or uploads a PHP file, this is not generated by the code release system, and an alert text message will be sent, and the alert file will be sent to the corresponding system engineer for viewing. Multiple servers have Session sessions and some logon operations. We use IP hash on the server Load balancer server. Different users are distributed to different servers based on different IP addresses. In addition, Session sharing is required on the PHP Web server. The following describes the application of PHP in Kingsoft game Operation System Keyes. Including a game, how to activate, broadcast, and other such information needs to be addressed through a platform. This is an architecture we designed, mainly divided into interface, interface and support, three-layer architecture design. From the earliest creation of the triangle is a management interface. Now many projects are also engaged in some IPI development. It is certain that IPI is a separate set, and the user interface on this site is also a set. However, we will make it completely An IPI, and perform operations on some data functions in the IPI interface. The management interface is just the logic of the management interface. I can view it in this operation management system. For example, some operation analysis systems also need to obtain online user information and access PHP for operations. This part on the right belongs to the game server, the Operation server on the left, and some game servers on the right. On the game server, the architecture of each game server is different. The server architecture is also cross-server, such as the network server. We operate each server with a daemon process. We use Knose for development and access through an encryption protocol. We access through multiple game processes, including developing some commands and sending some signals. when communicating with other games, we can monitor whether the process exists and the communication is normal. One possible scenario is that a game process exists. If the game is frozen internally, we use a PHP heartbeat and the game server process service, the server process is considered to be alive. Managing game servers from the outside involves a time issue. Because our external programs take a very short time, I am releasing a hold command. On the game server, we need to establish some user connections from the network side and save some user data, the game server can be stopped only after the entire process is completed. If many game servers are introduced, the data may be several dozen seconds to one minute. If you intervene from the front-end external users, timeout will be discovered, an external operation is required to be completed immediately. In this way, when we design an interface, we initiate a function interface from the PHP management interface, and this function interface is forwarded, and this request is complete, notify the various game processes to perform an evaluation operation. After the evaluation operation is completed, a new request is initiated to return to the PHP function interface, which turns into an asynchronous process. The following is a data interaction process, which consists of four functions. One is the operation command, which involves modifying the multiples of experience, kicking people, sending message broadcasts, starting the game, stopping the game, updating the game program, updating the configuration file, and server. The second is server monitoring, including CPU, disk, memory, number of processes, system load, and whether the game server process exists. Game heartbeat detection, Ping packet detection, determine whether the game is running normally, and check the total number of online players. We encountered this situation when developing this platform. A set of programs requires different game server architectures. Now we also lead some games in other companies to lead different game server architectures in other companies. In this way, how can we use a platform to adapt to each game studio or Game Development Company architecture. In the early stage, we must consider such a method. We provide An IPI interface to develop a game. According to the Protocol, we must access the game based on this IPI interface. Some problems will be found during actual development. When we need to access the operation system for various games, this game has basically become green. They may need to develop each game, and they will also use some frameworks, including the GSP Protocol framework. They have already been encapsulated and will be able to follow our protocol. If we develop it based on the interfaces we provide, there may be a problem in terms of time and cost. This is an example. If we send a bus to pick up, some people say that I like to drive by myself, and others may like to ride a motorcycle, which indicates that this encapsulates some frameworks, different protocols are processed. Some may be willing to accept this scheme. In this way, we need to modify the interface scheme to make every game R & D company adapt to our platform for fast access. This is a bit like driving a car. We are going to dispatch a bus to pick up the solution. We have changed a more open solution, and we are playing with various games, you only need to use the PHP protocol to communicate with us. Let's make a road design. If you want to build a road, you can either drive Audi or BMW or ride a motorcycle. We will formulate an agreement. You can follow this case. In this way, every game needs to follow our platform, but it also requires some constraints. For example, if I want to fly, it will certainly not work. Although it can give them more loose control, but you also need to observe certain rules. For example, if you cannot run a red light when you drive, you need to observe certain traffic rules. We can divide the game into binary protocols based on different games. For binary protocols, PHP is a streaming media, and we need to subscribe to it, some games have two bytes in the middle of a protocol package, indicating the length of the game package. We use the configuration file to set binary requirements. In the end, each protocol is different. The running system needs to parse the process and put it in the PHP function structure on the left. PHP development is very fast, and we can also analyze it very quickly. He uses a PHP mobile protocol to convert a game protocol into an IP request, so that PHP can easily resolve the game protocol. It may be very easy to parse the code, which is very fast at the development level. We intervened in three games in February March, simultaneously involved at the same time, and finally completed the intervention in the same period, which was also set from the structural design. Each game server has a different architecture and can only be defined as a process. Game decision-making may involve four processes. The above server is divided into different servers, and the following process is divided into different servers. The above three processes are used on Windows servers, and the remaining several are used on Linux. In this way, we organize the processes on the PHP external interface. Because the game server is ultimately organized by each process and these performances are organized, we can communicate with servers of different architectures. No matter how the architecture is designed, the game server operates two services on one server, or multiple servers operate a variety of services, no matter how the architecture changes, as long as the final positioning process can be solved, for different game compatibility, so as to achieve a universal platform, an architecture above the same architecture can be implemented. This is my speech today. Thank you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.