Jump to content
MakeWebGames

Optimising Brave Update


Snatchy

Recommended Posts

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

Link to comment
Share on other sites

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:        ; 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...