开发者

Should XML be used server-side, and JSON client-side?

开发者 https://www.devze.com 2022-12-30 18:54 出处:网络
As a personal project, I\'m making an AJAX chatroom application using XML as a server-side storage, and JSON for client-side processing.

As a personal project, I'm making an AJAX chatroom application using XML as a server-side storage, and JSON for client-side processing.

Here's how it works:

  1. AJAX Request gets sent to PHP using GET (chat messages/logins/logouts)
  2. PHP fetches/modifies the XML file on the server
  3. PHP encodes the XML into JSON, and sends back JSON response
  4. Javascript handles JSON information (chat messages/logins/logouts)

I want to eventually make this a larger-scale chatroom application. Therefore, I want to make sure it's fast and efficient.

Was this a bad design choice? In 开发者_Go百科this case, is switching between XML and JSON ok, or is there a better way?

EDIT:

Two mechanisms prevent a big server load when fetching information from the server:

  1. An "event id" is assigned to each message/login/logout, so all that's sent back to the user is the events his client hasn't yet processed.
  2. When an XML file becomes too big, a new one is created.


As far as I am concerned, JSON is always a good choice for async. data transfer, because it is not as bloated as XML is. I'd choose latter only if I want the data to be human readable, e.g. config files.

--- Edited: And remember: Serializing/deserializing XML is a performance issue and not particularly convenient for persisting web application data with high frequency access, while, as mentioned, using xml as config files is imo best practice.


Both XML and JSON are good for inter-applications communication. In Javascript, JSON is much easier than XML to deal with, so that's what I'd recommend.

As for storage... both are terrible as large datastores I'm afraid. MySQL would work better than editing a file, but it's still not an appropriate solution for a chat, especially if you're on a shared host. You may want to take a look at SQLite, perhaps creating one file per chat room.

0

精彩评论

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