This code consuming very hi server load

Started on the old forum in March 2011 · view the original in the archive · old links redirect here

14 replies · 922 views · started 15 years ago · 1 min read

6 participants
slowy Senior · 357 posts #1

hi all, plz help in dis,a php page is getting hi load on server. here is the 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();
?>
subzero Super moderator Fellow · 3,954 posts #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... _______…

subzero Super moderator Fellow · 3,954 posts #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... _______…

subzero Super moderator Fellow · 3,954 posts #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... _______…

akela Senior · 305 posts #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

External image (may be gone) Unlimited Web Hosting service. 99.99 $ uptime Guarantee. Free Trail Available for 30 days. Free Script | Null script| Php | Unlimited Web Hosting| Unlimited Space | Unlimited Bandwidth| Unlimited Domain| $3/m Unlimited Space | Unlimited Bandwidth|5 Domain| $2/m 10 GB Space | 100 GB Bandwidth| 1 Domain| $1/m FFMPEG| FREE SCRIPT | FREE SITE BUILDER |LIVE SUPPORT [Timewebhosting.com On Web Hosting| Unlimited Web Hosting](http://www…

kiss Senior · 294 posts #10
<?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 8) and here you can make a test Gzip Compression Test Good luck 🙂

www.inbuzunar.mobi -Your mobile portal pocket

GumSlone Administrator Principal · 1,690 posts #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

External image (may be gone)

subzero Super moderator Fellow · 3,954 posts #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... _______…

slowy Senior · 357 posts #13

videodesihot wrote: 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

akela Senior · 305 posts #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

External image (may be gone) Unlimited Web Hosting service. 99.99 $ uptime Guarantee. Free Trail Available for 30 days. Free Script | Null script| Php | Unlimited Web Hosting| Unlimited Space | Unlimited Bandwidth| Unlimited Domain| $3/m Unlimited Space | Unlimited Bandwidth|5 Domain| $2/m 10 GB Space | 100 GB Bandwidth| 1 Domain| $1/m FFMPEG| FREE SCRIPT | FREE SITE BUILDER |LIVE SUPPORT [Timewebhosting.com On Web Hosting| Unlimited Web Hosting](http://www…

asidana Junior · 42 posts #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

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close