/    Sign up×
Community /Pin to ProfileBookmark

Recommendation on storing string of information?

There are many ways to do this, but maybe some of you have some experience with this.

How to store simple settings? Something that has to be loaded on every single visit.

Something as basic as one dimensional array.

I’m Title
1.1
Welcome To The Site

First being a title to be used
Second being version of CSS file to use
Third being variable to be shown on website.

I’m seeking for top-performing possibility. Of course the “array” will be more than these 3 entries, but that’s just an example. I cannot hardcode it. It has be interchangeable by PHP script. Any recommendations by experience?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmJan 04.2017 — Why do you refer to using an array and not a database? The proper way to do this is to create a db table and define your three fields and place the data there. This will provide you the most flexibility and the easiest to implement, assuming that you are able to code up some simple scripts to do the updates and retrievals.
Copy linkTweet thisAlerts:
@NogDogJan 04.2017 — Could be in an include file that gets require()'d in by each applicable part of the application. That include file could simply define the array as static code, or it could read in a text file and parse it into an array (really simple with JSON files using json_decode), or XML if you like that sort of thing (I don't).

settings.json
<i>
</i>{
"title": "The Title",
"css_version": 1.1,
"message": "Welcome to the Site!"
}

config.php
[code=php]
<?php
$config = json_decode(file_get_contents(__DIR__.'/settings.json'), true);
if(empty($config)) {
// throw exception, or redirect to error page, or whatever???
}
[/code]
Copy linkTweet thisAlerts:
@HexiconauthorJan 04.2017 — Yea. That's the issue. I could implement either. But what would be faster, non-stop connection to the database, or non-stop I/O?
Copy linkTweet thisAlerts:
@NogDogJan 04.2017 — For something like that, I'd probably just do the file-based thing and not add a DB query for every page request. If you're worried about squeezing out every microsecond, you'd have to try both and measure the performance, as there would be many variables involved, from number of config params, disk speed and caching on the web server, DB server performance, etc., etc.... ?

My general rule of thumb is to avoid premature optimization and go with the simplest and most easily maintainable code; then start refactoring for optimization when you find a need and determine empirically where the delays are.
Copy linkTweet thisAlerts:
@ginerjmJan 05.2017 — Just realize that creating a static array locks you into something that will take manual effort to re-structure. A db approach (well-thought-out) will make it much easier to so something different later on, such as building a static array and storing it as an include file if that turns out to be the "speedier" approach.
Copy linkTweet thisAlerts:
@rootJan 05.2017 — IMHO you would like most sensible options, have a static name for your CSS as a hard link in the HTML and you would modify the CSS file with the changes as and when needed.

The page title could be a database entry along with the page content (which I assume you will be using some kind of content driven system) as well as any welcome message.

Some systems I have looked at use a template HTML page and the blanks are completed by retrieving the information in a database.
×

Success!

Help @Hexicon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...