Jump to content

php temporary storage of data? (other than database)


Goat

Recommended Posts

Greetings, people

 

I know it is possible to place small amount of data on server without using database. All session data is placed on server, not client, so anytime you put something in $_SESSION array, you are placing temporal data on server. I am pretty sure that's hella lot faster than putting it in database.

 

My question is simply this: Is it possible to place data in an array or something that would be available to all who come, not just current user (like SESSION), without using database? This is mostly needed in developing chat script, where optimization is  a key and databases are slow

Link to comment
Share on other sites

I am pretty sure that's hella lot faster than putting it in database.

 

Don't. You might be surprised. Database can be configured to store data in memory, which is 'hella lot' faster than storing anything in the file (as sessions by default do). Sessions can actually be configured to use database on the other hand.

 

My question is simply this: Is it possible to place data in an array or something that would be available to all who come, not just current user (like SESSION), without using database? This is mostly needed in developing chat script, where optimization is  a key and databases are slow

 

Don't know why you think databases are slow.

Other ways of persisting data is to store them in flat files (see fopen) but this induces several problems when too many people try to read/write same file at once.

Link to comment
Share on other sites

Maybe it's just perception, I don't know. I have assumed (mother of all fuckups I know) that databases most often hold data on hard drive (I know they don't have to but oh well...) while $_SESSION is held in RAM (and is therefore faster). I know lot of folks are saying database access is the biggest bottleneck

 

Is there some query or something that will force MySQL database to hold certain table in RAM whenever possible? I have full access to server, by the way, so I can configure or install anything I want.

 

Also how to cache certain queries in MySQL?

Link to comment
Share on other sites

MySQL tries to load table into RAM when data from table is accessed for the first time and keeps it there as long as it's accessed often enough that other tables don't need it's place. You need to give MySQL enough RAM to be able to store your most commonly used tables in memory. People often run their servers on default settings, which used to be really modest for a long time (and that's one of the reasons you hear of 'database bottleneck').

 

You will see a bit better performace in writing when using InnoDB database engine, because of the way it handles writes (I won't even try to explain it in detail because I hardly understand it myself ;) )

 

There's also a separate storage engine called MEMORY that will always store your data in memory. Be careful... on server restart, all data in such tables are lost. Because of this it might seem useless at first, but it has it uses (like caching aggregated data).

 

For query caching (useful thing indeed when used properly) see  http://dev.mysql.com/doc/refman/5.1/en/query-cache.html

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.