Haunted Dawg Posted February 18, 2009 Posted February 18, 2009 I've come to think of a way that a user can speed up there website by a ton. But if the member can not edit there session's which i hear is hard, then it's do able. $query = mysql_query("SELECT blah FROM users WHERE userid = x"); $query = mysql_fetch_assoc($query); Ok as you can see i have a complete normal SELECT query. $_SESSION['ir'] = $query; Now as you can see i am setting my session "ir" to the "query" array. To call this method. echo $_SESSION['ir']['blah']; Simple. But it can actualy save you a ton of resource ;). Why? Because on the login you run the query then use the session to call everything. Meaning, you do not have to select a ton of thing's per page load. Problem lies with the database updating. Now, since we actualy got a session of $query, it does not update all the time. So what we need to do now is make an updater. Every time you use a mysql query to update something in the database, which is alot, but not on every page load. You can simply use this: ses_update(); $_SESSION['update'] = 1; Add to your global_functions.php function ses_update() { if(isset($_SESSION['update'])) { if(isset($_SESSION['ir'])) { $query = mysql_query("SELECT blah FROM users WHERE userid = ".$_SESSION['ir']['userid']); $query = mysql_fetch_assoc($query); $_SESSION['ir'] = $query; unset($_SESSION['update']); } } return $_SESSION['ir']; } Now when you call out for example username: echo $_SESSION['ir']['username']; ETC, but i must still read up on editing $_SESSION[] data. don't post your hate mail here, send it to [email protected] thank's ;) Quote
Sim Posted February 18, 2009 Posted February 18, 2009 Re: Game Optimization if(isset($_SESSION['update'])) should be if(!empty($_SESSION['update'])) if we talking about optimization ;] Quote
Haunted Dawg Posted February 18, 2009 Author Posted February 18, 2009 Re: Game Optimization if(isset($_SESSION['update'])) should be if(!empty($_SESSION['update'])) if we talking about optimization ;] No. Because if "update" is set then we must do the update, hence why i had put ses_update(); $_SESSION['update'] = 1; Quote
POG1 Posted February 18, 2009 Posted February 18, 2009 Re: Game Optimization It is a good idea but why not just update the applicable attributes in the array instead of resetting it? surely it will be a bit faster. Quote
Haunted Dawg Posted February 18, 2009 Author Posted February 18, 2009 Re: Game Optimization Well, per page load you running alot of query's. Reduce this and you could save your self about 0.0050 second load. Which is fast actualy. Quote
POG1 Posted February 18, 2009 Posted February 18, 2009 Re: Game Optimization What i meant was instead of running ses_update() every time you update an attribute cant you just edit that attribute within the ir array in the session? Quote
Haunted Dawg Posted February 19, 2009 Author Posted February 19, 2009 Re: Game Optimization Yes you can, but you will need to fetch the new value. Quote
POG1 Posted February 21, 2009 Posted February 21, 2009 Re: Game Optimization mysql_query("UPDATE user SET money = money + 1000 WHERE userid = 1"); $_SESSION[ir][money] += 1000; Quote
Haunted Dawg Posted February 21, 2009 Author Posted February 21, 2009 Re: Game Optimization A [] without the '' take's longer to load ;) 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.