Storing Website Data - JSON vs SQL
I'm managing a website that is built from the ground-up in PHP and uses AJAX extensively to load pag开发者_如何学运维es within the site.
Currently, the 'admin' interface I created stores the HTML for each page, the page's title, custom CSS for that page, and some other attributes in JSON in a file directory (e.g. example.com/hi would have its data stored in example.com/json/hi/data.json).
Is this more efficient (performance-wise) than using a database (MySQL) to store all of the content?
EDIT: I understand that direct filesystem access is more efficient than using a database, but I'm not just getting the contents of a file; I need to use json_decode to parse the JSON into an object/array first to work with it. Is the performance hit from that negligible?
Your manner doesn't sounds very bad, in fact I used a not-so-far solution before and it does the job pretty good. But you might consider more powerful storage as soon as your admin will grow or the need to separate things arises. Since, there are two ways :
SQL : using relationnal database like Postgre or MySQL
No-SQL : which seems to be more of your interest, here is why.
Considering you're using ajax for communication and json for storage, there's MongoDB. A no sql approach to storage that use json syntax for querying. There even is an Interactive Tutorial for it !
When it comes to performances, no one sounds to be faster. Both engine usually written in C or C++, that is, for best performances. Nevertheless, for a structure as simple as you describe, there's no faster way than direct file access.
Thad depends on what you use that data for.
If you only serve 'static' files, with almost the same data all the time, then even static HTML files are recommended for chaching.
If, on the other hand, you process data and display it in multiple forms (searches, custom statistics, etc) then it is much better to store it in some kind of DB
精彩评论