Jump to content
MakeWebGames

ok need help Fast [mysql_slow_queries]


grant

Recommended Posts

ok as you no grpg has it own time updater for who online and stuff but mite is giving me slow queries witch is slowing my site down lags really bad when there is about 30 - 40 users on at one time

# Thu Dec 22 16:02:56 2011

# Query_time: 7.208091 Lock_time: 0.000047 Rows_sent: 0 Rows_examined: 1

use warror_wart;

UPDATE `warriorusers` SET `lastactive` = '1324594969' WHERE `id`='733'

# Thu Dec 22 16:09:36 2011

# Query_time: 3.630811 Lock_time: 0.000060 Rows_sent: 0 Rows_examined: 1

use warror_wart;

UPDATE `warriorusers` SET `lastactive` = '1324595372' WHERE `id`='186'

here is the code am using any help would be great thanks

 

i have this in my header

usertime($user_class->id, time());

 

this is in my classes

function usertime($user, $time){
$resultaf = mysql_query("SELECT * FROM `warriorusers` WHERE `id`='$user'");
$worked = mysql_fetch_array($resultaf);
$itemexist = mysql_num_rows($resultaf);
if($itemexist == 0){
} else {
$resultbb = mysql_query("UPDATE `warriorusers` SET `lastactive` = '$time' WHERE `id`='$user'");
}
}
Link to comment
Share on other sites

I mean the table schema.

It is possible that the mysql service is having conflict whilst converting data types, but with that amount of users it shouldn't slow down at all.

Try passing the timestamp and user id as integers to the database, rather than strings(as they are being sent currently).

Link to comment
Share on other sites

i try it but may need to change my game time timestamp to stop it from lagging as its pissing me off i have removed the code to see if it helps and the games not lagging any more so i just going to have to use some other way to get the users to show online and 24 list and i think the code not working to well going in to the db is there any way to make a 2 part table in the db for users to split the users in to 2 tables ?

Link to comment
Share on other sites

Firstly, you are creating an array that you don't even know exists, why?

Assuming warriorusers only has 1 row per user, you can use something like:

 

function usertime($user, $time) {
 $resultaf = mysql_query("SELECT `id` FROM `warriorusers` WHERE `id` = '{$user}' LIMIT 1");
 if(mysql_num_rows($resultaf)) {
   mysql_query("UPDATE `warriorusers` SET `lastactive` = '{$time}' WHERE `id` = '{$user}' LIMIT 1");
 }
}

not help wot ever way i put the code try 4 ways not helped one bit is there any other way to to grab the time without useing that $time(); ????? and thanks for the help

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...