chaoswar4u Posted January 14, 2010 Posted January 14, 2010 Well im on a mission of reducing my server load and come to the globals.php. Ive reduced query load by making the queries better via the header.php alone however is there anything that can be done in globals.php. The queries in globals run every page load so Im after gaining some more performance. I dont see anything that can be done myself but I may have missed something. Can the existing queries be better constructed??? Any info would be great. Many thx Chaos Quote
Zeggy Posted January 14, 2010 Posted January 14, 2010 Can you post your globals.php? You could also try optimizing your database so queries run faster. Quote
chaoswar4u Posted January 16, 2010 Author Posted January 16, 2010 HI sorry. Was assuming everyone has the file to check this. The queries I refer to are - global $jobquery, $housequery; if($jobquery) { $is=$db->query("SELECT u.*,us.*,j.*,jr.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid LEFT JOIN jobs j ON j.jID=u.job LEFT JOIN jobranks jr ON jr.jrID=u.jobrank WHERE u.userid=$userid"); } else if($housequery) { $is=$db->query("SELECT u.*,us.*,h.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid LEFT JOIN houses h ON h.hWILL=u.maxwill WHERE u.userid=$userid"); } else { $is=$db->query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid"); } $ir=$db->fetch_row($is); Can these queries be improved. Thet are usally in effect the most so if any performance can be gained I wish to take it. Quote
Zero-Affect Posted January 17, 2010 Posted January 17, 2010 Them queries so they can be used to pull every single column in all of the selected tables so i wouldn't think there is a way, short of predefining all columns at beginning of files and inputting that above require "globals.php"; (possible), i may actually do this unless someone thinks of a better solution. Quote
AlabamaHit Posted January 19, 2010 Posted January 19, 2010 What I did with my engine I'm working on. Is I just make a query to call what I need on each page. I didn't make a laggy page lol. Quote
seanybob Posted January 19, 2010 Posted January 19, 2010 In the past, I thought about optimizing it like so: On EVERY mccode page, add a string variable above the include "globals.php"; line. The string character will contain a comma separated list of all the fields from the users table used on that page. E. G. $userfields=",crytalbank, crystalsstored"; In globals.php, the query would look like: $db->query("SELECT money,exp,username,userid{$userfields} WHERE userid=$userid "); or something along those lines. So in globals.php you would have it load all the variables that are used on every page like username/money/level, and then in the userfields variable have it store (and thus, load) those variables that are only used on specific pages. May not be the most efficient, but that's the idea I had floating around in my head. Quote
Zero-Affect Posted January 20, 2010 Posted January 20, 2010 main file <?php $information_user = '`username`, `userid`'; include "globals.php"; echo $ir['username'].' '.$ir['userid']; ?> globals $ir... if ( !empty($information_user) ) { $sql = sprintf('SELECT $information_user FROM `users` WHERE `userid` = %u', $userid); $is = mysql_query($sql); } else { $sql = sprintf('SELECT * FROM `users` WHERE `userid` = %u', $userid); $is = mysql_query($sql); } doesn't seem so hard Quote
wolfe Posted January 21, 2010 Posted January 21, 2010 This idea intrigues me a bit, although i do not think i will be attempting it for an existing game. Would be something i would try for a game that is not open and in the case of Mccodes is being rewritten page by page. Quote
a_bertrand Posted January 21, 2010 Posted January 21, 2010 As I already stated to Zerro in the chat, this would in principle have some impact if your web server and mysql server are 2 different machines. However on the same machine (as most of the setups are), you don't really see much of difference, if any. At least that's what I saw from my own experiences. Quote
Zero-Affect Posted January 21, 2010 Posted January 21, 2010 so is that general optimizing or just simply this method of this query? Quote
a_bertrand Posted January 21, 2010 Posted January 21, 2010 Well basically what I saw is the following: Unless a full table row is REALLY huge, doing a select * is not much slower (if even slower) than a select a,c,e,z From my point of view, this make sense as the database will need to somehow read the row basically.... and just give you the data back you asked. Also, if your queries changes all the time, it would not be possible to MySQL to cache the query results. Therefore you could even have worse results. On the other side, if you need to transfer the query over the network, all bytes counts, and therefore returning just what you need is faster. As always, don't trust my words, do some checks by yourself and tell me if you get different results. Quote
chaoswar4u Posted January 22, 2010 Author Posted January 22, 2010 Many thanks for the feedback on this people. Lol seems to have made an impact. Quote
wolfe Posted January 22, 2010 Posted January 22, 2010 Well basically what I saw is the following: Unless a full table row is REALLY huge, doing a select * is not much slower (if even slower) than a select a,c,e,z From my point of view, this make sense as the database will need to somehow read the row basically.... and just give you the data back you asked. Also, if your queries changes all the time, it would not be possible to MySQL to cache the query results. Therefore you could even have worse results. On the other side, if you need to transfer the query over the network, all bytes counts, and therefore returning just what you need is faster. As always, don't trust my words, do some checks by yourself and tell me if you get different results. It would be interesting to see at what point the row is large enough to start eliminating fields from the query. I've altered a few event queries to only select what is needed instead of all of it (read, time, etc). I noticed a big difference in speed but i didnt record the actual time variance. I'm sure the amount of data in the table impacts this as well. Quote
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.