开发者

Static Array vs Mysql + PHP vs XML file to update via ajax

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

Example:

Boot [Color1,Color2,Color3,Color5]
Shoes [Color开发者_Go百科1,Color2,Color3,Color5]

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.

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

Thanks


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.

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.

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.


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.


That depends on how you plan to use the data. If you want this data to be permanently available I would say the best way us with a php and a database. Otherwise if its just for a one time use, you could store this data in a static array. Hope this helps.


BEST depends on balancing maintainability and performance and where your skillset is strongest.

If performance is paramount, encode each color as RGB value #rrggbb and then each boot by its ID.

Then name every image with the values, such as: 00FF00_42.jpg for the green boot of style #42 boot.

If you need the green boot of ID #42, you just ask for images/00FF00_42.jpg and completely bypass PHP, database, and any other kind of lookup.

This will scream for performance, but making sure you have all 28000 X 5000 images named correctly will require some infrastructure work.

Another option, you could have a bitmask grayscale image for each boot style, and use http://php.net/gd or http://php.net/imagemagik to "colorize" it a la Ted Turner.

There is still no DB, and you'd want to "cache" the images that are popular.

The basic point is this: There is no real need to "store" colors. They are going to end up RGB in the end, and you can just use the hex color codes. (Unless these are destined for print media where it's not really RGB color model...)

So you really just need a clear and simple way to organize your 5000 boots, which is pretty simple, really.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜