I had an account suspended on a paid, shared web host recently. They said it was because one of my php pages was taking up more than 10% CPU time. What's shocking is that looking at the reports, it was nearly 10 times that!
Now I have a hunch as to why this happened. Here's a bit of code from buy.php:
$query = "SELECT * FROM `users` WHERE `username` = '".$luser."'";
$result = mysql_query($query);
$num = mysql_numrows($result);
$i=0;
while ($i < 1) {
$money =@mysql_result($result,$i,"money");
$query = "SELECT * FROM adoptables WHERE uid = '$aID'";
$result = @mysql_query($query);
$num = @mysql_numrows($result);
//Loop out code
$i=0;
while ($i < 1) {
$aID=@mysql_result($result,$i,"uid");
$name=@mysql_result($result,$i,"name");
$imageurl=@mysql_result($result,$i,"imageurl");
$cost=@mysql_result($result,$i,"description");
if($money < $cost){
$article_title = "Oops";
$article_content = "You don't have enough bits to afford $name. <a href='shop.php'>Go back</a>.";
}
else {
I noticed that when the conditions met that If statement, the page would time out.
So I added
$i++;
}
to close the output of both those queries, and now it loads fine.
So my question to you php freaks is:
Is it likely that not closing the output properly caused this much load on the CPU?
I don't get much traffic to my site.