Author Topic: Storing array data in .php file  (Read 565 times)

Offline Delifisek

  • Level 12
  • *
  • Posts: 79
  • Reputation: +1/-1
    • View Profile
Storing array data in .php file
« on: February 13, 2009, 05:53:42 PM »
Hello there.

I want to share one of my methods to improve php performance especially game development.

I'm 10+ expert php developer who has interesing a php bbg

So...

In every php example shows tells you to use SQL as data stroage. And SQL was primary bottleneck of the your php bbg. here opcode cache friendly (read here as if you use APC, XCACHE, ZEND ENCODER or PHP6  your code faster by x 10 or x 20 under heavy load) solution for sql caching.

Code: [Select]
<?php
//--- note 42 was level 6 drider id

if(is_file('cache/monsters/level6_drider.php')) {
    require(
'cache/monsters/level6_drider.php');
} else {
    
$sql "SELECT attr_name, attr_val FROM monters WHERE id = '42'";
    
$res mysql_query($sql);
    while(
$row mysql_fetch_assoc($res)) {
        
$drider6[$row['attr_name'] = $row['attr_val'];
    }
    
//--- Here trick comes
    
file_put_contents('cache/monsters/level6_drider.php',"<?php /** Drider 6 data on ".date('d.m.Y H:i:s',mktime())." */\n\n\$drider6 = ".var_export($$drider6,true).";\n?>
");
}

Now you have Opcode cache friendly cache. Very easy method to escaping SQL overhead.

And if you play with drider data don't forget to delede cache.

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: Storing array data in .php file
« Reply #1 on: February 14, 2009, 12:17:33 AM »
And if level 6 monsters are changed your screwed, unless you create an admin panel that deletes that file when you change it.

Nice idea when say.. I'm creating a blog.. For games I'll stick with mySQL. I may be slower but I can be more agile and hey if the game is getting the amount of hits where this would be beneficial then I'll just throw more hardware at it... hardware is cheap, my coding isn't :)~

Creating online addictions, one game at a time:

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal