This code consuming very hi server load

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

    This code consuming very hi server load

    hi all,
    plz help in dis,a php page is getting hi load on server. here is the code
    PHP Code:
    <?php
    include("conf.php");
    include(
    "func.php");
    Connect($dbserver,$dbname,$dbuser,$dbpass);
    $dt=Date("Y-m-d");
    $tdt=date("Y-m-d");
    $lrd=mysql_fetch_array(mysql_query("SELECT text FROM misc where dscr='CLR'"));
    $lrd=strtotime($lrd[0]);
    $nrd=mktime(0,0,0,date("m",$lrd),date("d",$lrd)-2,date("Y",$lrd));
    $ddt=date("Y-m-d",$nrd);
    $sid        $_GET["sid"];
    $ip            $_SERVER['REMOTE_ADDR'];
    $sql        "SELECT * FROM sites where id='".$sid."' and banned='0';";
    $sites        mysql_fetch_array(mysql_query($sql));
    $date        date("Y-m-d");
    // Check Unique IP in table visitor
    $check_ip    mysql_fetch_row(mysql_query("SELECT ip FROM visitor WHERE ip='".$ip."' and date='".$date."' and sid='".$sid."'"));
    if(empty(
    $check_ip))
    {
        
    mysql_query("INSERT INTO visitor SET date='".$date."', ip='".$ip."', sid='".$sid."'");
        
    $hosts    $sites[ur]+1;
        
    mysql_query("UPDATE sites SET ur='".$hosts."' WHERE id='".$sid."'");
        
    /* Update Total Hosts
        $thost    = $sites[thost]+1;
        mysql_query("UPDATE sites SET thost='".$thost."' WHERE id='".$sid."'");
        */
    }
    //Update Today & Total Hists
    $thits        $sites[9]+1;
    $dhits        $sites[8]+1;
    $res        mysql_query("UPDATE sites SET dhits='".$dhits."', thits='".$thits."' WHERE id='".$sid."'");
    $week_day     date("w");
    $today         date("Ymd");
    // Today 
    $result1    "SELECT ur FROM sites WHERE id='".$sid."' LIMIT 1;";
    $result        mysql_query($result1);
    $row        mysql_fetch_array($result);
    $host_today    $row['ur'];
    //--------------------- Place on top --------------------------
    $result1    "SELECT * FROM sites WHERE ur >= $host_today ORDER BY ur DESC;";
    $result        mysql_query($result1);
    $top_place    mysql_num_rows($result);
    $total        "SELECT thits FROM sites WHERE id='".$sid."' LIMIT 1;";
    // Online Users
    $timestamp    time();
    $timeout    $timestamp 900;
    $del_online    mysql_query("DELETE FROM online WHERE timestamp<$timeout");
    $check_on    mysql_fetch_row(mysql_query("SELECT ip FROM online WHERE sid='".$sid."' and ip='".$ip."'"));
    if(empty(
    $check_on))
    {
        
    $insert    mysql_query("INSERT INTO online VALUES('".$sid."','".$timestamp."','".$ip."')");

    else 
    {
        
    $result    mysql_query("UPDATE online SET timestamp='".$timestamp." WHERE ip='".$ip."''");
    }
    $online        mysql_num_rows(mysql_query("SELECT * FROM online WHERE sid='".$sid."'"));
    if(
    $c=="" OR $c=="1")
    {
        
    Header("Content-Type: Image/GIF");
        
    $image_file=ImageCreateFromGIF("images/count11.gif");
        
    $font_color=ImageColorAllocate($image_file,128,64,0);
        
    $fc=ImageColorAllocate($image_file,0,0,0);
        
    $tfc=ImageColorAllocate($image_file,10,10,10);
        
    $font_file="images/visitor2.ttf";
            
    ImageTtfText($image_file,10,0,36,12,$font_color,$font_file,"HOST:");
        
    ImageTtfText($image_file,10,0,36,20,$font_color,$font_file,"HITS:");
            
    ImageTtfText($image_file,14,0,10,20,$fc,$font_file,"$top_place");
        
    ImageTtfText($image_file,10,0,70,10,$fc,$font_file,"$host_today");
        
    ImageTtfText($image_file,10,0,70,20,$fc,$font_file,"$dhits");
            
    ImageTtfText($image_file,14,0,125,20,$fc,$font_file,"$online");
        
    ImageGIF($image_file);
        
    ImageDestroy($image_file);
        exit;
    }
    elseif(
    $c=="2")
    {
        
    Header("Content-Type: Image/GIF");
        
    $image_file=ImageCreateFromGIF("images/count22.gif");
        
    $font_color=ImageColorAllocate($image_file,128,64,0);
        
    $fc=ImageColorAllocate($image_file,0,0,0);
        
    $tfc=ImageColorAllocate($image_file,10,10,10);
        
    $font_file="images/visitor2.ttf";
            
    ImageTtfText($image_file,9,0,15,34,$fc,$font_file,"$top_place");
            
    ImageTtfText($image_file,11,0,27,57,$font_color,$font_file,"ONLINE:");
        
    ImageTtfText($image_file,10,0,22,45,$font_color,$font_file,"$host_today");
        
    ImageTtfText($image_file,10,0,62,45,$fc,$font_file,"$dhits");
            
    ImageTtfText($image_file,14,0,70,57,$fc,$font_file,"$online");
        
    ImageGIF($image_file);
        
    ImageDestroy($image_file);
        exit;
    }
    elseif(
    $c=="3")
    {
        
    Header("Content-Type: Image/GIF");
        
    $image_file=ImageCreateFromGIF("images/count33.gif");
        
    $font_color=ImageColorAllocate($image_file,128,64,0);
        
    $fc=ImageColorAllocate($image_file,0,0,0);
        
    $tfc=ImageColorAllocate($image_file,10,10,10);
        
    $font_file="images/visitor2.ttf";
            
    ImageTtfText($image_file,14,0,30,30,$fc,$font_file,"$online");
        
    ImageGIF($image_file);
        
    ImageDestroy($image_file);
        exit;
    }

    mysql_close();
    ?>

    http://WapTops.com- Get Real High Traffic
    http://WapFun.info-Fun 4 Wap

    #2
    What script you used ?
    Visit: Chat4u.mobi - The New Lay Of being a site of your dreams!
    Visit: WapMasterz Coming Back Soon!
    _______
    SCRIPTS FOR SALE BY SUBZERO
    Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders.
    FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others...
    _______
    Info & Tips
    php.net
    w3schools.com

    Comment


      #3
      its a script of image counter in toplist

      http://WapTops.com- Get Real High Traffic
      http://WapFun.info-Fun 4 Wap

      Comment


        #4
        Gzip + Image flatten
        Visit: Chat4u.mobi - The New Lay Of being a site of your dreams!
        Visit: WapMasterz Coming Back Soon!
        _______
        SCRIPTS FOR SALE BY SUBZERO
        Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders.
        FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others...
        _______
        Info & Tips
        php.net
        w3schools.com

        Comment


          #5
          Originally posted by subzero View Post
          Gzip + Image flatten
          not getting u

          http://WapTops.com- Get Real High Traffic
          http://WapFun.info-Fun 4 Wap

          Comment


            #6
            any1 there 2 help me???????????????

            http://WapTops.com- Get Real High Traffic
            http://WapFun.info-Fun 4 Wap

            Comment


              #7
              Search a Gzip

              <?php
              if(substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
              ob_start("ob_gzhandler");
              else
              ob_start();
              ?>
              Enjoy @@!!@@
              Visit: Chat4u.mobi - The New Lay Of being a site of your dreams!
              Visit: WapMasterz Coming Back Soon!
              _______
              SCRIPTS FOR SALE BY SUBZERO
              Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders.
              FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others...
              _______
              Info & Tips
              php.net
              w3schools.com

              Comment


                #8
                Originally posted by subzero View Post
                Search a Gzip



                Enjoy @@!!@@
                not working, same result

                http://WapTops.com- Get Real High Traffic
                http://WapFun.info-Fun 4 Wap

                Comment


                  #9
                  yes, count.php are consuming more server resources and so i try many server to host the toplist but each hosting are suspended the site as toplist then i finally removed the toplist script from the site.
                  sure, need to vps and server for toplist hosting

                  Comment


                    #10
                    PHP Code:
                    <?php
                    if(isset($_SERVER["HTTP_ACCEPT_ENCODING"]) && substr_count($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip"))
                    ob_start("ob_gzhandler");
                    else
                    ob_start();
                    include(
                    "conf.php"); 
                    include(
                    "func.php"); 
                    Connect($dbserver,$dbname,$dbuser,$dbpass); 
                    $dt=Date("Y-m-d"); 
                    $tdt=date("Y-m-d"); 
                    $lrd=mysql_fetch_array(mysql_query("SELECT text FROM misc where dscr='CLR'")); 
                    $lrd=strtotime($lrd[0]); 
                    $nrd=mktime(0,0,0,date("m",$lrd),date("d",$lrd)-2,date("Y",$lrd)); 
                    $ddt=date("Y-m-d",$nrd); 
                    $sid        $_GET["sid"]; 
                    $ip            $_SERVER['REMOTE_ADDR']; 
                    $sql        "SELECT * FROM sites where id='".$sid."' and banned='0';"
                    $sites        mysql_fetch_array(mysql_query($sql)); 
                    $date        date("Y-m-d"); 
                    // Check Unique IP in table visitor 
                    $check_ip    mysql_fetch_row(mysql_query("SELECT ip FROM visitor WHERE ip='".$ip."' and date='".$date."' and sid='".$sid."'")); 
                    if(empty(
                    $check_ip)) 

                        
                    mysql_query("INSERT INTO visitor SET date='".$date."', ip='".$ip."', sid='".$sid."'"); 
                        
                    $hosts    $sites[ur]+1
                        
                    mysql_query("UPDATE sites SET ur='".$hosts."' WHERE id='".$sid."'"); 
                        
                    /* Update Total Hosts 
                        $thost    = $sites[thost]+1; 
                        mysql_query("UPDATE sites SET thost='".$thost."' WHERE id='".$sid."'"); 
                        */ 

                    //Update Today & Total Hists 
                    $thits        $sites[9]+1
                    $dhits        $sites[8]+1
                    $res        mysql_query("UPDATE sites SET dhits='".$dhits."', thits='".$thits."' WHERE id='".$sid."'"); 
                    $week_day     date("w"); 
                    $today         date("Ymd"); 
                    // Today  
                    $result1    "SELECT ur FROM sites WHERE id='".$sid."' LIMIT 1;"
                    $result        mysql_query($result1); 
                    $row        mysql_fetch_array($result); 
                    $host_today    $row['ur']; 
                    //--------------------- Place on top -------------------------- 
                    $result1    "SELECT * FROM sites WHERE ur >= $host_today ORDER BY ur DESC;"
                    $result        mysql_query($result1); 
                    $top_place    mysql_num_rows($result); 
                    $total        "SELECT thits FROM sites WHERE id='".$sid."' LIMIT 1;"
                    // Online Users 
                    $timestamp    time(); 
                    $timeout    $timestamp 900
                    $del_online    mysql_query("DELETE FROM online WHERE timestamp<$timeout"); 
                    $check_on    mysql_fetch_row(mysql_query("SELECT ip FROM online WHERE sid='".$sid."' and ip='".$ip."'")); 
                    if(empty(
                    $check_on)) 

                        
                    $insert    mysql_query("INSERT INTO online VALUES('".$sid."','".$timestamp."','".$ip."')"); 
                    }  
                    else  

                        
                    $result    mysql_query("UPDATE online SET timestamp='".$timestamp." WHERE ip='".$ip."''"); 

                    $online        mysql_num_rows(mysql_query("SELECT * FROM online WHERE sid='".$sid."'")); 
                    if(
                    $c=="" OR $c=="1"

                        
                    Header("Content-Type: Image/GIF"); 
                        
                    $image_file=ImageCreateFromGIF("images/count11.gif"); 
                        
                    $font_color=ImageColorAllocate($image_file,128,64,0); 
                        
                    $fc=ImageColorAllocate($image_file,0,0,0); 
                        
                    $tfc=ImageColorAllocate($image_file,10,10,10); 
                        
                    $font_file="images/visitor2.ttf"
                            
                    ImageTtfText($image_file,10,0,36,12,$font_color,$font_file,"HOST:"); 
                        
                    ImageTtfText($image_file,10,0,36,20,$font_color,$font_file,"HITS:"); 
                            
                    ImageTtfText($image_file,14,0,10,20,$fc,$font_file,"$top_place"); 
                        
                    ImageTtfText($image_file,10,0,70,10,$fc,$font_file,"$host_today"); 
                        
                    ImageTtfText($image_file,10,0,70,20,$fc,$font_file,"$dhits"); 
                            
                    ImageTtfText($image_file,14,0,125,20,$fc,$font_file,"$online"); 
                        
                    ImageGIF($image_file); 
                        
                    ImageDestroy($image_file); 
                        exit; 

                    elseif(
                    $c=="2"

                        
                    Header("Content-Type: Image/GIF"); 
                        
                    $image_file=ImageCreateFromGIF("images/count22.gif"); 
                        
                    $font_color=ImageColorAllocate($image_file,128,64,0); 
                        
                    $fc=ImageColorAllocate($image_file,0,0,0); 
                        
                    $tfc=ImageColorAllocate($image_file,10,10,10); 
                        
                    $font_file="images/visitor2.ttf"
                            
                    ImageTtfText($image_file,9,0,15,34,$fc,$font_file,"$top_place"); 
                            
                    ImageTtfText($image_file,11,0,27,57,$font_color,$font_file,"ONLINE:"); 
                        
                    ImageTtfText($image_file,10,0,22,45,$font_color,$font_file,"$host_today"); 
                        
                    ImageTtfText($image_file,10,0,62,45,$fc,$font_file,"$dhits"); 
                            
                    ImageTtfText($image_file,14,0,70,57,$fc,$font_file,"$online"); 
                        
                    ImageGIF($image_file); 
                        
                    ImageDestroy($image_file); 
                        exit; 

                    elseif(
                    $c=="3"

                        
                    Header("Content-Type: Image/GIF"); 
                        
                    $image_file=ImageCreateFromGIF("images/count33.gif"); 
                        
                    $font_color=ImageColorAllocate($image_file,128,64,0); 
                        
                    $fc=ImageColorAllocate($image_file,0,0,0); 
                        
                    $tfc=ImageColorAllocate($image_file,10,10,10); 
                        
                    $font_file="images/visitor2.ttf"
                            
                    ImageTtfText($image_file,14,0,30,30,$fc,$font_file,"$online"); 
                        
                    ImageGIF($image_file); 
                        
                    ImageDestroy($image_file); 
                        exit; 


                    mysql_close();
                    ob_end_flush();
                    ?>
                    Now will working and here you can make a test Gzip Compression Test Good luck
                    www.inbuzunar.mobi - Your mobile portal pocket

                    Comment


                      #11
                      gzip would not reduce the server load, it will increase it a bit, depends on the compression level, but it it will reduce the bandwidth usage, you should optimize your mysql queries and my.cnf file
                      Advertise your mobile site for FREE with AdTwirl

                      Comment


                        #12
                        My chat site is Gzip 3 times
                        Visit: Chat4u.mobi - The New Lay Of being a site of your dreams!
                        Visit: WapMasterz Coming Back Soon!
                        _______
                        SCRIPTS FOR SALE BY SUBZERO
                        Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders.
                        FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others...
                        _______
                        Info & Tips
                        php.net
                        w3schools.com

                        Comment


                          #13
                          Originally posted by videodesihot View Post
                          yes, count.php are consuming more server resources and so i try many server to host the toplist but each hosting are suspended the site as toplist then i finally removed the toplist script from the site.
                          sure, need to vps and server for toplist hosting
                          i m on core i7 dedi server, but its effects the other of my sites, coz page loads slowly

                          http://WapTops.com- Get Real High Traffic
                          http://WapFun.info-Fun 4 Wap

                          Comment


                            #14
                            yes, that true. on shared hosting if any site consuming more resources then other site will be slow.
                            Gumslone is right as you should optimize your mysql queries and my.cnf file

                            Comment


                              #15
                              I'm no php person and the problem seems to be related too many queries to your sql server. try to reduce queries and create indexes on your table. indexes help quite a lot. best to index columns you query a lot for example id, but; do not over kill indexing.

                              i do smilar count hits on some sites and have only one select, one insert and one update

                              Comment

                              Working...
                              X