"Zhang Banquet" application of PHP in the operation of Jinshan games

Source: Internet
Author: User
Tags php development environment nginx server nginx load balancing

PPT1 (Foreign server): Http://blog.s135.com/attachment/201105/2011phptc_zy.zip

PPT2 (Domestic server): http://ishare.iask.sina.com.cn/f/15231659.html

Original: http://blog.s135.com/2011phptc/

Hello everyone, now I come to share with you is PHP in the Kingsoft game operations, including team development, as well as the system structure, design, operational platform information. I have two main issues, one is the official website of Jinshan games to do some applications, but also in the Jinshan game operating system Keyes application. Kingsoft Official website includes customer service, some ask, know and so on, including some games related products, this block mainly uses Linux system, 64 bit, PHP is 5.2 version.

We first look at team collaboration development, we certainly have encountered a situation, in many of our projects now are many people engaged in the development of a project, but also related to the development environment and test environment is different. We use PHP all the use of Windows, but a lot of people in the Linux development code, I finished a certain function, want to see the results immediately, then on the Windows can also be equipped with the corresponding platform, but we also developed some like PHP extension to operate some, if distributed image processing, Some caching systems, these are some PHP extensions developed for Linux under PHP. Therefore, the Windows platform is not available.

This piece of hope to write a program can be seen immediately, but we do not need to write a program to the server to re-test, it is too slow. If there are many people on the same server who develop at the same time, you may be able to cover other people's programs, there is no way to control. We can see that we use the PC mode of the Windows development environment that is programmer a, as we can see from above, if programmers A and B both develop code on Windows, we can put nginx on Windows, we develop programs in Windows, Each programmer is tested and can be debugged after testing so that the results of execution are performed under Linux.

From this process can be seen, first of all a programmer he obtained a project version, to make some changes, after the modification can be used in debugging the same Linux test server. After his test is complete, there is no problem at this level, can be submitted to my SVN repository, can do an automatic synchronization program, including Linux development and test server. This SVN synchronization will automatically notify Linux to update the latest code. Later found that there is a problem, if our program file is very much, before SVN very slow, so the programmer after the test, submit svn and so on.

We are for convenience, because we need to make a prediction, we have a virtual host every day, we add a virtual host on the left, add the virtual host will be the current directory on Linux. This can be seen in the following this is the entire process can be set tosts for native IP, on their own computer, modify a file, local debugging No problem can be submitted. Write code PHP code files in Windows, debugging with the Linux environment PHP, to ensure that the development environment, test environment generation Environment unified. The entire PHP development environment, testing environment, that is, to ensure that the programmer's rapid changes, the mode of code requirements, but also ensure that the entire code in SVN version control.

Development environment this time again encounter such a problem, the PHP Code unity guarantee. We are in the development environment first to the offline test environment, after offline testing to the online test environment, and finally to the formal environment, there are many kinds of environment. In addition, we develop a number of projects, about 10 projects, many projects connected to MySQL, Memcached, interface IP, texting, query user data on their ports are different, programmers are often wrong, or a group of fog, so who best understand the server adapter, is certainly a system engineer, This requires separating the two. Let the most familiar with this business to do, so we have developed a PHP extension, there is a kae-config management background, we on each server through a background to publish, need to do is the system engineer in different environments, different server systems, configuration different parameters, different IP ports.

After each PHP version has been unified, including PHP files to unify, it involves the release of PHP code online. Do not know what other companies do, we put the line released this piece, to each project responsible for the development of the program owner to do, this piece can be a system engineer from the release of code. From the release of the release, if we want to release a 1.0 version, this is 2.1.46 version, can be corresponding to, if I want to send the User Center 2.1.46 version, you can correspond to 21901, two versions and the last version, if there are changes between the 20,000 version, We can get it through PHP. When the system is released, we can only publish this file.

So we developed a code publishing background, from the above two red places can be seen, we added a new release number, there is a major version, minor version. In this case, each engineer will develop a version, including a project, can have a different person responsible for the commercial release, each online will submit relevant information. From the right button we can see that we are going to launch which version, we can release the version, if we find this version on the line, if there is a major problem, if it takes a long time to resolve, immediately back to the previous version, with each version of the release of the content version control, so that the entire release at a glance.

Third, PHP and open source products, C + + program combination. Using the PHP Client extension, the TCP/C + + Open source program communicates with the Sphinx, for example, search and so on. Mode two, we are developing some HTTP-based protocols to communicate with C + + open source programs, such as open source simple Message Queuing software developed with our glyphs, and HTTPQS to communicate. PHP Web programs, Web applications require that each request be very fast, processing speed needs to be resolved at the millisecond level. We also encounter a number of services, such as texting, as well as sending mail will take a few 10 seconds, which allows users to wait on the front page of the user experience is not good.

and upload videos, we need video format conversion, and we do data mining, we need to record some information about the user, record some logs, so we need to process asynchronously. In order to solve asynchronous processing, we are also divided into two situations. One is short time-consuming asynchronous processing, consuming 1, 2 seconds, recording some of the digital mining information, which may take less time, we can use PHP-FPM to provide fastcgi-finish-reques function. From the start of this function, the user will not wait for the result below, so that some async can be implemented.

fastcgi-finish-reques function Disadvantages. The phpfastcgi process has a limited number of processes and is processing the PHP-CGI process for asynchronous operations and cannot process new requests. If the number of concurrent accesses is large, the php-cgi process is full, and the new access request will not have php-cgi amount to handle. Nginx server will appear, 502 bad operation to take a queue to resolve, including open-source queue. In this case, in our product application, we apply to some of the following clear we send text messages, we can first into the queue, and finally from the queue to send mail, like refreshing the front page cache, the benefit of making the above video page conversion can be resolved asynchronously.

We use a PHP load balancer, from this frame composition is a general game of our website architecture. Can see there are forums, there are some common PHP services, the most front-end we use two servers to balance, the following larger business like some forums, or game activities, a separate set of PHP external server. This is distributed through load balancer to the following PHP for duty processing, from PHP to the back end will be connected to some, just now we mentioned some like distributed image processing, some search engines, like these interfaces to operate.

Of course we are in the development of services, because we have more than one Web server, we also need to be aware of PHP development. The previous stand-alone program in order to cache recently, if placed on more than one server, may survive on this server, there is no survival on that server. In addition, each visit will generate a lot of small files, small files will occupy a lot of Linux browsing, and sometimes the disk is not finished, but there is no way to create a new file, because a lot of small cache files, resulting in the entire application full. So I use APC, memcached instead of the data object cache.

There is also HTML output page cache, we use the front-end nginx load balancer to make a cache. Nginx load Balancing can now also support caching, and dynamically access some content to the backend Web server for caching. If it is some long-term page, like the game official website, like some pictures can not only change. There is a advantage, the Web server, PHP files can be unified management through the Code publishing system, add, delete Web server, very fast, clear the cache, can be unified management by the system engineer.

In addition to the code tamper-proof, in case a customer upload Trojan up, but also in our PHP program to develop a pre-judgment to do a resolution. Because our PHP program is published through the code system, can let it execute, if not through our Code distribution system published programs, if he created a PHP file above, or upload a php file, this is not through the code release system generation, and will send an alarm message, The alarm files are given to you by the appropriate system engineer to view. Multiple servers have session sessions, and there are some login actions. We use a server to do IP hash on the load balancer, different users according to different IP distribution to different servers. In addition, it is necessary to do session sharing on Phpweb server.

Below is the application of PHP in Jinshan game operation System Keyes. Including a game, how to Live, send a broadcast, etc. this information needs to be solved through a platform. This is a structure we designed, mainly divided into interface, interface and support, three-layer architecture design. From the earliest to do the triangle is a management interface, now a lot of projects also carried out some IPI development, Affirmation IPI is a separate set, the site's own use of the interface is a set. But we're going to make it completely a ipi, some of the functions of the data in the IPI interface, the management interface is just the logic to implement the management interface. I am in this operation management system can be viewed, such as some business analysis system, also need to obtain the user online information, can be transferred to PHP operation.

On the right this part belongs to the game server, the left is the operation server, the right is some game server. Game server, involving each game service side architecture is not the same, he also includes a server-side architecture is also across servers, such as network-side servers. We operate a daemon on each server, we use knose development, and we access it through an encryption protocol. We access through multiple game processes, including developing some instructions, sending some signals, communicating with him in the game, having we can monitor the existence of the process, and whether the process and communication are normal.

There may be a situation, one is the game process exists, if because the game inside zombie, this time we through a PHP heartbeat, game server process Services, we think this server process is alive. From the outside to manage the game server, this piece of us involves a time problem. Because our external program takes time very fast, I release a stagnation instruction, in the game server need to build a user some connection from the network side, and save some user data, he completes the whole process can stop the whole game service end, if introduce more, guarantee the data may be a few 10 seconds to 1 minutes, From the front-end external users to intervene will find the time-out situation, external need to do an operation can be completed immediately. So we go to design the interface, we from the PHP management interface, we launch a functional interface, this function interface is forwarded, this request is completed, to notify each game process to do an evaluation operation, after the evaluation operation to launch a new request to go back to this PHP function interface, so , it becomes an asynchronous process.

The following is a data interaction process, divided into four functions. One is the operating instructions, which involves modifying the experience multiplier, kicking people, sending messages to broadcast, starting the game, stopping the game, updating the game program, updating the configuration file, and serving. The second is server monitoring, including CPU, disk, memory, number of processes, system load, and the existence of a game service-side process. Game heartbeat detection, ping packet detection, determine whether the game is running properly, there are games online number, to see the total number of games online.

When we developed this platform, we encountered this situation, a set of programs need different game server architecture. Now we also lead other companies some games, lead other companies game server architecture is not the same, so we go to use a platform to adapt to each game studio, or game development company architecture. In the early days we were definitely thinking about such a method, we provide an IPI interface, develop a game, follow them all to follow this protocol, follow this IPI interface to access. To the actual development of the time will be found to encounter some problems, we in various games need to access the operating system, the game has basically been formed, to the green state. Each of them may need to do some, they will also use some framework to develop, including the GSP framework, they have been encapsulated, can immediately follow our agreement to do.

If developed in accordance with the interface we provide, there may be a problem in terms of time and cost. This is what we do for example, if we send a bus to pick up, some people say I like to drive, maybe someone else like to ride a motorbike, which means that the package framework, the processing of the protocol is different. There may be more willing to accept the plan, so that in order to enable each game development company can adapt to our platform for fast access, we need to transform the interface scheme.

It's kind of like we're driving, we're going to send a bus to get the plan, we changed a more open plan, we and each game, you just use the PHP protocol and we communicate on it, we go to do a road design. We build a road, you want to drive Audi BMW can, want to ride a motorcycle can also, we will develop a protocol case, you want to follow this set of examples can be. In this way each game needs to follow our platform, but this also requires some constraints, such as I want to fly a plane come to definitely not, although can give them more relaxed restrictions, but also need to abide by some rules, such as you drive to the red light, need to obey some traffic rules. We will be divided into binary protocols according to different games, because the words of the binary protocol, PHP is a streaming media hideitsu we need to subcontract, some games in a protocol package in the middle of some two bytes represents the length of the game package. We use the config file to set the binary requirements.

Finally, each protocol is different, the operating system needs to parse out this part of the process, put on the left PHP functional structure. PHP is developing very quickly and we are also going to parse him a rest very quickly. He passed a php flow protocol, and we went through a conversion and converted it into an IP request so that PHP could simply parse the game protocol so that it could be done easily. It might be very easy to parse the code, which is very fast from the development level. We were involved in three games in March, at the same time, and at the end of the same period, it was set up from the structural design.

Each game server architecture is different, and ultimately it can only be defined as a process. Game decision this part may have four processes, the above server is divided into different servers, the following process is divided into different servers. The above three processes take advantage of the Windows Server, and a few of them are used on Linux, so we have an organization in the external interface of PHP to face the process. Because the game server is ultimately organized by each process, these performance organizations, we can communicate with different architecture servers, no matter how the architecture is designed, is a server operating two services, or multiple servers operating a variety of services, no matter how the architecture changes, as long as the final positioning process can be resolved, For different game compatibility, this will be able to achieve a common platform, to achieve an architecture architecture.

This is my speech for today, thank you.

"Zhang Banquet" application of PHP in Jinshan game operation

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.