Simple PHP control site concurrent number

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

In general, A project there will always be some difficult processing business, For instance business complex variety of search, Use the search systems such as Sphinx, Lucence etc. to deal with., The data source if the change too fast (such as top, trample, browse number etc.), First push data on the frequency of difficult to measure, Also cannot accurate search or sort. So the general approach is to search through DB, And in addition to the business to the decomposition of the program level, Also add a layer of cache before DB. But it also has the disadvantages of many known:
1, in fact many business cannot be placed in the treatment of common PHP, As some of the more sophisticated sorting, screening, To achieve the common words of PHP efficiency is less than MYSQL.
2, cache hit rate is not good guarantee, Especially for some use the keyword query service, Keywords too much change.

If encounter malicious brush., The DB server is easy to hang directly, So we can be a limiter is added to the program level, Limit the number of concurrent, The limiter has the following characteristics:
1, high efficiency (nonsense., Otherwise, direct brush limiter is maxed out). Now is the use of Memcache atomic operation count, Can be extended to use other methods.
2, accurate to action layer. Can separate confinement single page.
3, convenient. Different people, different views. It
4, low cost. Including the cost of research and development and the cost of hardware.

According to the pressure measuring, originally only 100 concurrent search function, limit 100, pressure measuring results of 800 normal.

The following code:

     * Search
    public function search(){
        //Increase the counter function, more than the number of returns the system is busy
        $viewlimiter = Library::load('viewlimiter');
        //Name to access the limiter, please use controller+action to a single page, remain the only
        $limitName = 'search_search';
        //At the same time access number
        $limit = 100; 
        //If more than the number of directly returns
        if(!$viewlimiter->check($limitName, $limit)) {
            ajaxOutput(0, $this->lang->line('multi_search_limit'));

        /*- complex business logic, metamorphosis*/
    //end func

Expand the topics:
1, if the business is brush, May cause normal users are unable to view content. The problem to be solved is to operate from the system level, The visible side:;
2, limits the number of the best combination and cache hit rate, Automatic change limit range, To raise the limit accuracy. The later can be studied, The combination of   and cache class;
3, according to the server load for dynamic control. - related to the underlying and server permissions, Research on high cost, Are interested can study.

This paper illustrates ideas, The specific code for some reason not to open

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Enid at October 27, 2013 - 7:46 PM