check server load and if a server is buisy block download/ad request.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    check server load and if a server is buisy block download/ad request.

    Displaying ads on a site causes a high server load,
    here is a code to check the server load and if its low then show an ad.


    PHP Code:
    if(current_load()<50){
    echo 
    admob_request();
    }

    function 
    current_load()
    {
    //GET SERVER LOADS
    $loadresult = @exec('uptime');
    preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$loadresult,$avgs);
    return 
    $avgs[1];

    Advertise your mobile site for FREE with AdTwirl


    #2
    Thanks for the code.
    Could you explain the values in the array please? What each one means? Thanks.
    Perfection comes at a cost



    I accept liberty!

    Comment


      #3
      Originally posted by frostymarvelous View Post
      Thanks for the code.
      Could you explain the values in the array please? What each one means? Thanks.
      this are average server loads
      Advertise your mobile site for FREE with AdTwirl

      Comment


        #4
        Originally posted by GumSlone View Post
        Displaying ads on a site causes a high server load,
        here is a code to check the server load and if its low then show an ad.


        PHP Code:
        if(current_load()<50){
        echo 
        admob_request();
        }

        function 
        current_load()
        {
        //GET SERVER LOADS
        $loadresult = @exec('uptime');
        preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$loadresult,$avgs);
        return 
        $avgs[1];

        Better is my variant .
        PHP Code:
        # Gets system load average
         # $time - integer
         # 0 - system load average over the last minute
         # 1 - system load average over the last 5 minutes
         # 2 - system load average over the last 15 minutes
         # 3 - system load average array over the last 1, 5 and 15 minutes
        function server_load $time 

            
        # Gets system load average array
            
        $load sys_getloadavg ();
            
            return ( 
        $time == $load $load $time ] );
        }

        # Usage
        if ( server_load () < 50 
        {
            echo 
        admob_request(); 

        Comment


          #5
          I know that. When I diplayed the whole string, the loads were something like this.
          0.0, 0.1, 0.0
          How are these values gotten, and what they mean. That's what I wanted to understand.
          Perfection comes at a cost



          I accept liberty!

          Comment


            #6
            mine is up to 35-42 with just 300 users online :-/
            Unamos los corazones,hoy todos somos multicolores!

            Comment


              #7
              Originally posted by frostymarvelous View Post
              I know that. When I diplayed the whole string, the loads were something like this.
              0.0, 0.1, 0.0
              How are these values gotten, and what they mean. That's what I wanted to understand.
              Returns three samples representing the average system load (the number of processes in the system run queue) over the last 1, 5 and 15 minutes, respectively.

              Comment


                #8
                Originally posted by morency View Post
                mine is up to 35-42 with just 300 users online :-/
                try optimizing it, install memcached to cache mysql queries, also install nginx for static content and you will reduce your server load up to 10.
                Advertise your mobile site for FREE with AdTwirl

                Comment


                  #9
                  Thank you so much.
                  Perfection comes at a cost



                  I accept liberty!

                  Comment


                    #10
                    Originally posted by GumSlone View Post
                    try optimizing it, install memcached to cache mysql queries, also install nginx for static content and you will reduce your server load up to 10.
                    Hmmm .. I installed memcache ... I got some error , I restart the apache and WOW , have never seen the CPU under 10 :-O
                    Thanks for the tip Gum

                    L.E. : ok ..maybe this low usage is because of apache restart .. I will wait to see how will work today ..
                    Now average is 5-6 :D
                    Last edited by morency; 13.12.10, 14:54.
                    Unamos los corazones,hoy todos somos multicolores!

                    Comment


                      #11
                      thanks. Can you explain how uptime is related with server load?
                      Follow me @ksg91 | My Blog: http://ksg91.com | Nokia Blog: http://NokiaTips.in

                      Comment

                      Working...
                      X