0

I am developing a website using PHP and I'd like to know if it is better to store user preferences (such as language, background image, and so on) in a database or in a text file outside the public_html folder (to prevent public access to the info).

I ask this because I am worried about the time PHP takes to read a file and to send a query to the database, also it may slow down the database due the volume of queries sent by multiple users.

brasofilo
  • 25,496
  • 15
  • 91
  • 179
joaop
  • 75
  • 1
  • 12
  • 3
    There will always be trade offs to each one. If your user system is built around a database (which it probably is), store it in there. – SamT Sep 26 '13 at 17:11
  • 4
    I think the recommended preference would be to store the settings in a database, you could use $_SESSION to keep the data on hand while the user is connected, so you don't have to resend queries to get their settings on different pages. – Jason Sep 26 '13 at 17:14
  • My personal way of making this kind of decision is based on search. Is the data being put in the database being searched? If not, then it may make more sense on the file system. – SamA Sep 26 '13 at 17:16

4 Answers4

1

Usually I would store the user defined options in the database.

Some hints:

  • I load them only once in a request
  • sometimes I store all settings for a user in a blob if I have to use a relational database. This is dirty, but I can easily add new attributes
  • In high-traffic websites I would cache the retrieved object, using my MVC framework's cache mechanism
  • If caching to the file system becomes a problem, you can use databases like Redis, MemCached
herrjeh42
  • 2,782
  • 4
  • 35
  • 47
0

Usually we don't put files in the DB but read this and compare with your situation : https://stackoverflow.com/a/22804/1529139 and https://stackoverflow.com/a/3751/1529139

Community
  • 1
  • 1
56ka
  • 1,463
  • 1
  • 21
  • 37
0

Sorry for language problem ..

It is fully depends on your behavior of site. In which type of your project made. If you are using a MVC structure then create any directory at place of your bootstrap php page. Mean a main page. And store your source at that place.

Then make setting menu (Page ) for particular that will help to dynamically change the source identity and location path.

Punit Patel
  • 351
  • 2
  • 11
0

Storing in DB should be prefered, expecialy if later you have to load Balance between servers.

Supernini
  • 591
  • 5
  • 8