duanjiao6730 2012-05-07 08:48
浏览 27

PHP选项地图讨论

Every site should have options, changeable via a Control Panel. My new project is going to have this. However, I am curious as to which is the best method for storing these options.

Here are my known methods:

I have tested these, although not very thoroughly, as in all likelihood I will not find the long-term problems or benefits.

  1. Using a MySQL table with fields key and value, where each column is a new key/value pair. The downside to this is that MySQL can be slow, and in fact, would require a loop before every page to fetch the options from the database and parse it into an array.

  2. Using a MySQL table with a field for each value and a single record. The downside to this is that each new options requires a new field, and this is not the standard use of MySQL tables, but a big benefit is that it requires a single function to bring it into a PHP indexed array.

  3. Using a flat file containing the options array in serialized form, using the PHP functions serialize and unserialize. The main problem with this method is that I would have to first traverse to the file, read in the whole file, and serializing can be slow, so it would get slower as more options are created. It also offers a small layer of obfuscation to the data.

  4. Using an ini file. Ini parser's are rather fast, and this options would make it easy to pass around a site configuation. However, as above, I would have to traverse to the ini, and also, using an ini file with PHP is generally unused.

  5. Other formats, such as XML and JSON, have all been considered too. However, they all require some sort of storage, and I am mostly curious about the benefits of each kind of storage.

These are my specific idealistic requirements:

So the basic thing I am looking for is speed, security, and portability. I want the configuration to not be human readable (hence, an unencrypted flat file is bad), be easily portable (ruling out MySQL), and have almost zero but constant performance impact (ruling out most options).

I am not trying to ask people to write code for me, or anything like that. I just need a second pair of eyes on this problem, possibly bringing up points that I never factored in. Thank you for your help

Thank you- Daniel.

  • 写回答

1条回答 默认 最新

  • doudao9915 2013-05-15 07:53
    关注

    Using a MySQL table with fields key and value, where each column is a new key/value pair. The downside to this is that MySQL can be slow, and in fact, would require a loop before every page to fetch the options from the database and parse it into an array.

    That is false. Unless you plan on storing couple hundred million configuration pairs, you will be fine and dandy. If you worry about performance using this method, simply cache the query (and wipe the cache only when you make changes inside the table). This will also give you most flexibility, ease of use and so on.

    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口