/    Sign up×
Community /Pin to ProfileBookmark

Need advice on server cpu overload, checking my php files for the problem

My host sent me a message saying something on my hosting account was causing an overload on the shared resources

Username # procs CPU time Memory Usage


—————- ——- ———————- ————————

bwconline 41764 10640 secs (0.25/proc) 406.73 GB (9.97 MB/proc)

Im using godaddy shared linux hosting

What i need to know is, is there an easy/simple way to check the php scripts on my site and find out what file/code is causing the overload so i can figure out how to fix it before they cancel my account (i have a month)

Thanks

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@BWWebDesignsauthorJun 25.2009 — Well according to my host this is one file that has been really over working it recently and could be causing problems if it is not optimized properly bt im not sure if there is anything wrong with the code

[CODE]<?php
include ("../dbsettings.php");

$loginParams = mysql_connect("$dbhost", "$dbusername", "$dbpass");
mysql_select_db("$dbname",$loginParams);

$dmid=$_GET['dmid'];
$resulta = mysql_query("SELECT * FROM hosted_meters WHERE dmid = '$dmid' LIMIT 1");
$rowa = mysql_fetch_array($resulta);
$month = date("m");
$monthlygoal = $rowa['monthlygoal'];
$userid = $rowa['userid'];
$mname = $rowa['mname'];
$ppcc = $rowa['ppcc'];
if($ppcc=="GBP") {
$cursym = chr("163");
}elseif(($ppcc=="USD") or ($ppcc=="AUD") or ($ppcc=="CAD") or ($ppcc=="HKD") or ($ppcc=="NZD") or ($ppcc=="SGD")) {
$cursym = chr("36");
}elseif($ppcc=="EUR") {
//$cursym = "&#8364;";
//$cursym = "&#8364;";
$cursym = " ";
}elseif($ppcc=="JPY") {
$cursym = chr("165");
} else {
$cursym = "";
}

$donorslt = $_GET['lt'];
$resultb = mysql_query("SELECT * FROM authuser WHERE id = '$userid' LIMIT 1");
$rowb = mysql_fetch_array($resultb);
$membership = $rowb['team'];
$branding = $rowa['branding'];
if($membership=="Monthly") {
$branding = "Provided By DonationBooster.info";
} elseif($membership=="Yearly") {
$branding=="";
} elseif($membership=="Lifetime") {
$branding = $rowa['branding'];
} else {
$branding = "Provided By DonationBooster.info";
}

if($rowb['status']!="active") {
header("Location: http://www.donationbooster.info/hdm/images1/donation-meter-inactive.png");
exit;
} else {

$goal = $rowa['goal'];
if($monthlygoal=="y") {
$result = mysql_query("SELECT * FROM hosted_donations WHERE dmid = '$dmid' AND month = '$month'");
$monthlytext = "monthly ";
} else {
$result = mysql_query("SELECT * FROM hosted_donations WHERE dmid = '$dmid'");
$monthlytext = "";
}

$row = mysql_fetch_array($result);
while ($row) {
$donation = $row['donation']+$donation;
$fees = $row['fees']+$fees;
$row = mysql_fetch_array($result);
}

//$goal = number_format(str_replace(",","",$goal),2);

//$donation = number_format(str_replace(",","",$donation),2);
//$donation = number_format($donation,2);

$fees = number_format(str_replace(",","",$fees),2);



$goal = str_replace(",","",$goal);

$new_value2 = str_replace(",","",$donation);//number_format($donation,2);
$new_value = $new_value2;
$total = $new_value-$fees;
$per = $total / $goal;
$res = $per * 100;
$res = number_format($res, 0);

$current = $donation;
$width = 60;
$height = 160;
$widthfull = 250;
$heightfull = 250;
$font = 0;
$mcolor = $_GET['mc'];
if($mcolor=="") {
$mcolor = $rowa['metercolor'];
}
$tcolor = $_GET['tc'];
if($tcolor=="") {
$tcolor = $rowa['textcolor'];
}
$bcolor = $_GET['bc'];
if($bcolor=="") {
$bcolor = $rowa['backgroundcolor'];
}
$bocolor = $_GET['boc'];
if($bocolor=="") {
$bocolor = $rowa['bordercolor'];
}


$bar = 0.25;

function html2rgb($color){

if ($color[0] == '#') {

$color = substr($color, 1);

}

if (strlen($color) == 6) {

list($r, $g, $b) = array($color[0].$color[1], $color[2].$color[3], $color[4].$color[5]);

} elseif (strlen($color) == 3) {

list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);

} else {

return false;

}

$r = hexdec($r); $g = hexdec($g); $b = hexdec($b);

return array($r, $g, $b);
}

$metercolor = html2rgb($mcolor);
$textcolor = html2rgb($tcolor);
$backgroundcolor = html2rgb($bcolor);
$bordercolor = html2rgb($bocolor);

// create the image
$image = imagecreatetruecolor($widthfull, $heightfull);
$bg = imagecolorallocate($image,$backgroundcolor[0],$backgroundcolor[1],$backgroundcolor[2]);
$bo = imagecolorallocate($image,$bordercolor[0],$bordercolor[1],$bordercolor[2]);
$fg = imagecolorallocate($image,$metercolor[0],$metercolor[1],$metercolor[2]);
$tx = imagecolorallocate($image,$textcolor[0],$textcolor[1],$textcolor[2]);
$black = imagecolorallocate($image,0,0,0);

// Build background
imagefilledrectangle($image,0,0,$widthfull,$heightfull,$bg);
// Build background Outline
imagerectangle($image,0,0,$widthfull-1,$heightfull-1,$bo);

// Build bottom bulb
imagearc($image, $width/2, $height-($width/2), ($width/2), ($width/2), 0, 360, $fg);
imagefilltoborder($image, $width/2, $height-($width/2), $fg, $fg);

// Build "Bottom level
imagefilledrectangle($image,($width/2)-(($width/2)*$bar),$height-($width-15),($width/2)+(($width/2)*$bar),$height-($width/2),$fg );

// Draw Top Border
imagerectangle($image,($width/2)-(($width/2)*$bar),4,($width/2)+(($width/2)*$bar),($height+15)-$width,$fg);

// Fill to &#37;
imagefilledrectangle($image,($width/2)-(($width/2)*$bar),(($height+19)-$width) * (1-($current/$goal))+4,($width/2)+(($width/2)*$bar),($height+15)-$width,$fg );

// Add tic's
/* for( $k=0; $k<125; $k+=25 ) {

imagefilledrectangle( $image,
($width/2)+(($width/2)*$bar) -5,
($height-$width) - ($height-$width)*($k/100) -1,
($width/2)+(($width/2)*$bar) -1,
($height-$width) - ($height-$width)*($k/100) +1, $tx );


imagestring($image, $font,
($width/2)+(($width/2)*$bar) +2,
(($height-$width) - ($height-$width)*($k/100)) - (imagefontheight($font)/2),
sprintf( "%2d", $k),$tx);
} */

// Add % over BULB
$pct = sprintf( "%d%%", ($current/$goal)*100 );

imagestring($image, $font+2, ($width/2)-((strlen($pct)/2)*imagefontwidth($font+2)),
($height-($width/2))-(imagefontheight($font+2) / 2),
$pct, $tx);

$stringa = number_format($goal, 2);
//if($new_value2<$goal) {
$redgreena = $fg; //imagecolorallocate($image, 255, 0, 0);
//} else {
//$redgreena = imagecolorallocate($image, 0, 205, 0);
//}

$string2a = "1. ";
$string2b = "2. ";
$string2c = "3. ";
$string2d = "4. ";
$string2e = "5. ";
//Tell gd2, where your fonts reside
putenv('GDFONTPATH='.$_SERVER['DOCUMENT_ROOT']."/PayPalDonationMeter/hdm/images2/fonts/");
$fontttf = 'arial';
//$fontttf = $_SERVER['DOCUMENT_ROOT']."/PayPalDonationMeter/hdm/images2/fonts/arial.ttf";

imagettftext($image, 12, 0, ($widthfull/3)-strlen($mname), 35, $tx, $fontttf, $mname);
imagettftext($image, 8, 0, 113, 60, $tx, $fontttf, "We've raised");
$textbelow = $cursym.$total." of our ".$monthlytext."goal so far!";
$deducttb = 47;
imagettftext($image, 8, 0, $deducttb, 75, $tx, $fontttf, $textbelow);

$textbelow2 = $cursym.$fees." PayPal Fees";
$deducttb2 = 47;
if($_GET['rpf'!=1]) {
imagettftext($image, 8, 0, $deducttb2, 90, $tx, $fontttf, $textbelow2);
}
imagettftext($image, 8, 0, 43, 14, $redgreena, $fontttf, $cursym.$stringa);
//imagestring($image, 2, 43, -2, $stringa, $redgreena);
imagestring($image, 2, 40, 150, $string2a, $tx);
imagestring($image, 2, 40, 170, $string2b, $tx);
imagestring($image, 2, 40, 190, $string2c, $tx);
imagestring($image, 2, 40, 210, $string2d, $tx);
imagestring($image, 2, 40, 230, $string2e, $tx);
imagestringup($image, 1, 0, 245, $branding, $tx);

if($donorslt=="l") {
$string3 = "Latest 5 Donors";
imagestring($image, 2, 90, 130, $string3, $tx);
$count=162;
$latestdonors=array();
$result = mysql_query("SELECT * FROM hosted_donations WHERE dmid = '$dmid' ORDER BY id DESC LIMIT 5");
$row = mysql_fetch_array($result);
while ($row) {
//$dated=gmdate($dateformat, $row['time'] + $zone);
imagettftext($image, 8, 0, 60, $count, $tx, $fontttf, $row['name'].' Gave '.$cursym.number_format($row['donation'],2));
$count = $count+20;
$row = mysql_fetch_array($result);
}
} elseif($donorslt=="t") {
$string3 = "Top 5 Donors";
imagestring($image, 2, 102, 130, $string3, $tx);
$count = 162;
$result = mysql_query("SELECT * FROM hosted_donations WHERE dmid = '$dmid' ORDER BY donation DESC LIMIT 5");
$row = mysql_fetch_array($result);
while ($row) {
//$dated=gmdate($dateformat, $row['time'] + $zone);
//imagestring($image, 2, 60, $count, $row['name'].' Gave '.$pound.$row['donation'], $tx);

imagettftext($image, 8, 0, 60, $count, $tx, $fontttf, $row['name'].' Gave '.$cursym.$row['donation']);

$count = $count+20;
$row = mysql_fetch_array($result);
}
}
//$image2 = "paypal_donation_btn.png";
$image2 = "btn_donate_SM.png";
$image2 = imagecreatefrompng($image2);
imagealphablending($image2, 1);
imagecopy($image,$image2,100,98,0,0,74,21);

if($ppcc=="EUR") {
$image3 = "euro.png";
$image3 = imagecreatefrompng($image3);
imagealphablending($image3, 1);
imagecopy($image,$image3,40,6,0,0,6,8);

$image4 = "euro.png";
$image4 = imagecreatefrompng($image4);
imagealphablending($image4, 1);
imagecopy($image,$image4,92,76,0,0,6,8);

$image5 = "euro.png";
$image5 = imagecreatefrompng($image5);
imagealphablending($image5, 1);
imagecopy($image,$image5,46,81,0,0,6,8);
}

// send the image
header("content-type: image/png");
imagepng($image);
}
unset($row);
unset($rowa);
unset($rowb);
mysql_close();
?>[/CODE]
×

Success!

Help @BWWebDesigns spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...