Jump to content

How to create a settings section?


AzizLight

Recommended Posts

Hello everybody,

 

I am creating my own blogging engine using CodeIgniter. I am at the point where I need to create a settings section.

Now I know how to do this, it's easy. My problem is that I can't choose where to store the settings. Now please don't hesitate to correct me if I'm wrong:

  • I want to be able to change the settings, so putting them in a config.php file is not convenient.
  • I will use the settings fairly often. For example, the blog name will be use on every single page. So storing the config in a database will end up being very heaving since there will always be one additional database request each time I go to a new page.
  • I thought about putting xml, but I don't know what are the pros and cons of this solution...
  • What about json?yaml?any other better solution?

 

I also want to keep my blogging engine kind of minimalistic and fast if possible. What is the "best practice" when creating settings sections? what do you suggest I use? what is the best solution permormance-wise? what is the lightest solution solution?

 

Link to comment
Share on other sites

I appreciate your answer, but I was expecting something a bit more developped. Why XML? I heard XML was slow (which might very well be false). And is XML appropriate for that task? (there is always a right tool for the right task, XML is not appropriate for all the tasks)

Link to comment
Share on other sites

Initially I read this thinking you were storing settings for other users... but it seems this is a personal blog.  The storage medium should be dependent on how often they are accessed.

 

You mention that your blog name will change frequently... even such it would not change every minute, and even at every minute, MySQL wouldn't even notice.  However, I think you should use some sort of templating system for most of your "settings".  Your blog name / layout won't change very often and can be pre-compiled.  The same can be said for a list of articles you write.  You might add an article once or twice a day, but for the most part, there will be no need to pull the same data since it won't have changed.  Templating systems specialize in storing cached results until a certain period of time has passed, or the size of what it might be caching has changed on the server.

 

I have read that "smarty" is a good templating system(?), but do not use it myself.

Link to comment
Share on other sites

Thanks for your answer. I don't like templating systems, they bloat an application and are only useful for developement purposes: ie when there is a developer and a designer in a team and that the designer doesn't know how to use php, a templating system in that case can make things less complicated.

 

About cache, I think it's a good idea only when you post content in a regular basis, which is not my case. That is for the post. But for the settings it might be a good idea all the time. I would then replace the cache everytime the user change his settings.

 

Another solution I found is the following: sessions. Since the user settings are only relevent when a user is logged in, what I would do is retrieve the user settings when a user logs in and store them in the session, then remove them from the session once the user logs out. For site-wide settings cache might still be the bette solution, I have to think about it.

 

I have one question though. I heard parsing XML uses a good amount of CPU, which isn't convenient. But is that also the case for JSON and YAML. I have to say I am particularly curious about the YAML case.

Link to comment
Share on other sites

About cache, I think it's a good idea only when you post content in a regular basis

 

That kind of defies the point of caching? Caching allows regularly accessed data to be converted to static content for faster processing / inclusion. If you're updating the content all the time, you'd have to update the cache all the time; either case though it can still serve a useful purpose.

 

You're not being very clear as to what the settings are for. First post you mentioned blog settings like the title, now you're saying user settings? For user settings, as you said, sessions are most commonly used for this.

 

It could depend upon the complexity of the blog settings as to what storage method is right for you though. XML allows you to define much richer data, beyond just the simple 'property' : 'format' style. JSON isn't really meant for storing like a config file. It doesn't have the ability to remove / add nodes as XML does which could make modifying and updating your config file a bit bloated and slow. Perhaps cache the blog settings into JSON? I don't know much at all about YAML.

Link to comment
Share on other sites

I think YAML and JSON would be about the same.

 

BUT I don't think you'd have to worry about your settings being in a DB. Obviously caching is probably going to be the absolute fastest, but I think it would be overkill unless you were expecting the Digg effect to happen, or you already have quite a few readers. I know phpfreaks has a separate DB server, as do for a website I help develop, but look at the bottom of this page... example: Page created in 0.061 seconds with 18 queries. I think a DB would be just fine, maybe SOME caching using APC or what not.

Link to comment
Share on other sites

Thank you both for your answers. After getting advice for several forums and several people from IRC, I think I got my answer. For now I'm going to you a db without caching. Then if I ever open my site and if I happen to get the digg effect at some point, then I'll use caching. But I'm not there yet, and as you said (KingPhilip) caching is overkill. in my case at least.

 

By the way, if you happen to be bored and have nothing to do it would be nice if you could take a look at the the Blog Engine I'm developing (the one I'm talking about in this thread). I wouldn't mind get some critics on how I do things. It's available in github: http://github.com/AzizLight/CIMBlE

 

Once again thanks for your answers.

 

Aziz Light

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.