AzizLight Posted October 22, 2009 Share Posted October 22, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/178620-how-to-create-a-settings-section/ Share on other sites More sharing options...
Adam Posted October 22, 2009 Share Posted October 22, 2009 XML, it's the future! Quote Link to comment https://forums.phpfreaks.com/topic/178620-how-to-create-a-settings-section/#findComment-942172 Share on other sites More sharing options...
AzizLight Posted October 22, 2009 Author Share Posted October 22, 2009 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) Quote Link to comment https://forums.phpfreaks.com/topic/178620-how-to-create-a-settings-section/#findComment-942257 Share on other sites More sharing options...
xtopolis Posted October 23, 2009 Share Posted October 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/178620-how-to-create-a-settings-section/#findComment-942577 Share on other sites More sharing options...
AzizLight Posted October 23, 2009 Author Share Posted October 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/178620-how-to-create-a-settings-section/#findComment-942583 Share on other sites More sharing options...
Adam Posted October 23, 2009 Share Posted October 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/178620-how-to-create-a-settings-section/#findComment-942697 Share on other sites More sharing options...
Philip Posted October 24, 2009 Share Posted October 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/178620-how-to-create-a-settings-section/#findComment-943351 Share on other sites More sharing options...
AzizLight Posted October 24, 2009 Author Share Posted October 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/178620-how-to-create-a-settings-section/#findComment-943423 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.