PHP: optimum configuration storage?

こ雲淡風輕ζ 提交于 2019-12-01 22:14:13

Well, if memory isn't an issue, just serialize an array to a file. There is absolutely no faster solution than this. You don't have the I/O and library overhead of SQLite, and you don't have the network overhead of memcached.

But keep in mind, memory must really not be an issue. You'd be loading the entire 30,000 element array into memory at once, as opposed to using a database, where you could load them on an as-needed basis.

To structure the settings, you could put each in its own file.

But really, you should be using a database. That's what they're there for. I really question why you would need to worry about 30k settings..you might want to reconsider your application design.

How about in a database?

With a schema like this:

| key | value |

You could have data like this:

| currency | pound |
| timezone | GMT   |

It also means you can query it like this:

SELECT * FROM options WHERE key = 'timezone'

Or even return many options:

SELECT * FROM options WHERE key IN ('timezone','currency')

This can be in any kind of database, not least an SQLite database. If you're using a language such as PHP you can use ADOdb for database abstraction so your application is portable between different database types, just a thought if you were concerned about being tied down to one database.

If you want structured, I'd say ini files using the parse_ini_file function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!