开发者

Is it faster to use XML or Serialize() saving data to a DB in PHP?

I have a project that has a ridiculous amount of customization required.

As such, I am looking for a way that will be the fastest (or near fastest) at runtime and also be rock solid stable to save a variable number of customized fields.

For instance:

The two locations save the same 2 data fields.

At location #1, the two fields must be returned in number_format($num, 3) format while at location #2 those same two fields are text fields with no formatting required.

I am tryi开发者_StackOverflow中文版ng to find the best (as defined above) way to save/retrieve the format of these fields.

As of right now I am leaning towards saving in XML and serialize(), but during run-time, to optimize for speed, I would only be polling the serialize() data. This approach would alleviate my concerns about data corruption in the serialize() data as I can manually parse the data in the XML doc if necessary.

NOTE: I am just concerned with the formatting/style/etc of how to manipulate the fields for viewing, NOT the actual storing of the data in those fields.

I personally would rather not have to save this customization data as raw files on the server, since that is what a database is for and each location's customization data would be rather small (at most 40-50 fields).


Serialized values are not that easy to read (and edit) by humans compared to XML. However tools exist to parse serialized data, like the Serialized PHP library.

On the other hand, serialized values can be easily read back into variables, much easier than with XML. For XML You would need to create a "serializer" that is able to convert variables to XML and back. There is one in PEAR (XML_Serializer), another XML Serializer is available in Symfony2 as well.

Normally it's wise to not create a database inside a dabase. If you need to, ensure you can easily change that later on w/o changing your application design too much.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜