静态数组vs Mysql + PHP vs XML文件通过Ajax更新 [英] Static Array vs Mysql + PHP vs XML file to update via ajax

查看:45
本文介绍了静态数组vs Mysql + PHP vs XML文件通过Ajax更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有五个要素.每个元素都有5种颜色,我必须检索适合这些颜色的图片.

I have five elements. Each elements have 5 colors and I have to retrieve the pictures that fits those colors.

示例:

Boot [Color1,Color2,Color3,Color5]
Shoes [Color1,Color2,Color3,Color5]

第一个元素的可能性为28000,其他元素的可能性小于5000.通过ajax,我将发送颜色,并将返回图片.

The first element have 28000 posibilities the others has less than 5000. Via ajax I will send the colors and It will return the picture.

因此,哪一种是存储将要增长的数据的最佳方法:静态数组.具有Mysql数据库的PHP.或静态XML文件(其重量为1MB).

So Which is the best way to store data that are going to grow: Static Array. A PHP with a Mysql database. Or a static XML file (it can weight 1MB).

谢谢

推荐答案

如果将这些数据存储在静态XML文件中,则每次需要获取某些信息时都必须对其进行解析-这需要大量的信息.内存和CPU时间.

If you store those data in a static XML file, you'll have to parse it each time you want to get some information -- which takes it lots of memory and CPU-time.

如果使用太大的PHP数组,则会占用过多的内存,而且对性能的影响也不大.

If you use a too big PHP array, you'll take too much memory -- and it won't probably be that good for performances too.

使用SQL数据库(当然,具有适当的结构和索引)来存储数据并能够在有条件的情况下进行查询似乎是正确的主意.

To store data and be able to query it with conditions, using an SQL database (with the proper structure and indexes, of course) seems quite like the right idea.


在那之后,没有什么可以阻止您将某些缓存机制设置为(通常使用APC或memcached,甚至使用反向代理之类的清漆),以避免因相同的请求而频繁访问数据库


After that, nothing prevents you from putting some caching mecanism in place (using APC or memcached, typically -- or even a reverse-proxy like varnish), to avoid hitting the database too often with the same requests.

这篇关于静态数组vs Mysql + PHP vs XML文件通过Ajax更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆