Jump to content
MakeWebGames

Recommended Posts

Posted

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 ;)

Posted

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;

Posted

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.

Posted

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?

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