-2

I'm looking to store some basic information (just simple variables, not a database) which doesn't require any security (simple strings stored for case sensitivity, lets me skip a MySQL query to improve performance). I'm looking for quickest way to read the contents and create a few variables from those contents. I'm comfortable with how to interact with flat files for the most part, what I want to do is determine the most efficient way of storing a few variables and interpreting back in to PHP please.

PHP I'll store in the flatfile...

$case = 'My Site Name CaSiNG';
$string2 = 'some text';
John
  • 1
  • 13
  • 98
  • 177
  • 1
    Make it work. Then make it right. ***Then*** make it fast. By that point, you'll have a better idea of what's slowing you down anyway -- and frankly, i doubt it'll be reading "a few variables" no matter how you do it. – cHao Jan 04 '12 at 04:06

1 Answers1

1

This is fairly fast save for write blocking. I supposed you could also write your variables as strait php which should also be fast

$variables = array();
$variables['case'] = 'My site name';
$variables['string2'] = 'some text';

$write_to_file = serialize($variables);

// todo: save $write_to_file
// todo: open saved file and read contents to $write_to_file

$vars = unserialize($write_to_file);
print_r($vars);

see Convert var_dump of array back to array variable to use var_dump to export all your variables and import them

Community
  • 1
  • 1
useful
  • 472
  • 3
  • 6
  • I actually just came across serialize and unserialize at php.net. Thanks for actually answering the question and finding a thread where the poster's question was UP voted instead of ridiculed. Both accepted and up-voted. – John Jan 04 '12 at 05:21