Snatchy Posted September 13, 2007 Share Posted September 13, 2007 I am told by my server that this script is using to mahy resources. Is there any way i can optimise it and if so how do i go about this? <?php include "mysql.php"; global $c; //brave update $q1=mysql_query("SELECT COUNT(*) as users FROM users",$c); $r=mysql_fetch_array($q1); $rows=$r['users']; print "Found $rows users to process."; $i=1; $next=$rows; $query="UPDATE users SET brave=brave+((maxbrave/10)+0.5) WHERE brave$query2="UPDATE users SET brave=maxbrave WHERE brave>maxbrave"; $query3="UPDATE users SET hp=hp+(maxhp/3) WHERE hp$query4="UPDATE users SET hp=maxhp WHERE hp>maxhp"; mysql_query($query,$c) or die("\nError Executing Query 1 for updating users $i to $next\n$query\n".mysql_error()."\nError Code:".mysql_errno()); mysql_query($query2,$c) or die("\nError Executing Query 2 for updating users $i to $next\n$query2\n".mysql_error()."\nError Code:".mysql_errno()); mysql_query($query3,$c) or die("\nError Executing Query 3 for updating users $i to $next\n$query3\n".mysql_error()."\nError Code:".mysql_errno()); mysql_query($query4,$c) or die("\nError Executing Query 4 for updating users $i to $next\n$query4\n".mysql_error()."\nError Code:".mysql_errno()); print "\nUsers $i to $next updated successfully."; print "\nDone."; ?> Cheers Snatchy Quote Link to comment Share on other sites More sharing options...
hamster01 Posted September 13, 2007 Share Posted September 13, 2007 Re: Optimising Brave Update Take out all the useless shit lines that dabs added may help. <?php include "mysql.php"; mysql_query("UPDATE users SET brave=brave+((maxbrave/10)+0.5) WHERE brave<maxbrave "); mysql_query("UPDATE users SET brave=maxbrave WHERE brave>maxbrave"); mysql_query("UPDATE users SET hp=hp+(maxhp/3) WHERE hp<maxhp"); mysql_query("UPDATE users SET hp=maxhp WHERE hp>maxhp"); ?> Other than that, You really cant do much else without making the updates run on timestamps and remove crons i believe. Or try and do this; <?php include "mysql.php"; mysql_query("UPDATE users SET brave=brave+((maxbrave/10)+0.5) WHERE brave<maxbrave;UPDATE users SET brave=maxbrave WHERE brave>maxbrave;UPDATE users SET hp=hp+(maxhp/3) WHERE hp<maxhp;UPDATE users SET hp=maxhp WHERE hp>maxhp"); ?> But be sure your Mysql delimiter is ; This can be checked by typeing the following into your mysql command prompt: \s The result: mysql> \s -------------- c:/***/mysql.exe Ver 14.12 Distrib 5.0.37, for Win32 (ia32) Connection id: 3384 Current database: Current user: admin@**** SSL: Not in use Using delimiter: ; Quote Link to comment Share on other sites More sharing options...
Decepti0n Posted September 13, 2007 Share Posted September 13, 2007 Re: Optimising Brave Update http://au2.php.net/manual/en/function.m ... .php#76991 Quote Link to comment Share on other sites More sharing options...
hamster01 Posted September 13, 2007 Share Posted September 13, 2007 Re: Optimising Brave Update http://au2.php.net/manual/en/function.m ... .php#76991 Oh, I thought It would work, since it sends the data to the mysql server. Hmm.. Quote Link to comment Share on other sites More sharing options...
UCC Posted September 13, 2007 Share Posted September 13, 2007 Re: Optimising Brave Update Are you running on a free server or a POS cheap server? I would guess that is the likely problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.