How would I store website settings? Something that needs to be accessed every more often than the SQL database. But requires no index. A one-dimensional array that will have to be processed every single time user visits the website.
in a file?
I’m sure there are a number of ways other than a database.
Maybe a simple CSV text file.
Or a PHP include file that just sets an array and is included/required in every script/page that needs it.
Isn’t it way slower than SQL database? Wouldn’t that be heavy bottleneck or slowdown?
Also, it has to be dynamicable.
Now I’m confused.
You posted “store website settings”
This suggests to me something like a type of configuration file containing CONSTANTs would be adequate.
But now you post “has to be dynamicable”
I don’t see how website settings would need to change all that often.
So maybe you mean User settings?
If so, then yes, using a database would be a good idea.
The simplest way to store website settings would be a PHP file
<?php
$cfg['db_host'] = "..";
...
$cfg['admin_email'] = "..";
Isn’t it way slower than SQL database? Wouldn’t that be heavy bottleneck or slowdown?
No.
It must be editable from outside means (using PHP script) and apply immediately. Those “website settings” are more than what you think, we’re talking about couple thousand constant entires. Sometimes they require adding, editing and removing.
Are there no “better” ways than store heavy requested one-dimensional array in the database?
Is it really a one-dimensional array or simply a couple of thousand scalar values?
How about one-dimensional array with couple thousand simple string/scalar values?
Without knowing what these couple of thousand values are we are still playing a guessing game.
IMHO “couple thousand values” sounds like a potential resource drain that is a result of a poor design decision that didn’t take scalability into consideration and things have now gotten out of control.
Anyway, if the main concern is the frequent calling in of the values, be it from a file or a database, then I think assigning them once to the SESSION array may be the way to go unless you can address the root cause of the issue instead of treating the symptoms.
Well settings, I don’t know how to specify you to it.
Another good example would be IP ban list. With array something like:
$banned = ("127.0.0.1", "::1:", "192.168.1.1");
It could be edited pretty much every millisecond during DDoS attack.
And current IP needs to be tested against array items thoroughly.
I know there are 5 billion ways to attempt mitigating DDoS attack, but this is just to give you an idea.
I don’t know how to simply you “settings for the websites”.
Pretty straightforward. One-dimensional array of information, that needs to be processed, and must be editable by PHP script at any time (adding, editing, changing).
you store them in many ways and a database is fine as well but understand that if speed is your concern the database will be on the slower side as well.
Other options include custom txt files, xml, json, ini, a php file with array items external db systems or api’s really you can do this in so many ways that are dynamic and can be accessed by outside programs. And they all will suit your needs.
Isn’t I/O slower than database?
Also, “external db systems”? What is the difference between one system and second system? They’re both databases after all.
No not at all and the database uses IO anyways an optimized version but still they both in the end save data to files. There is no magic land that databases use to save its data they save it in highly optimized and compressed files when all is said and done. But there is also faster ways of doing IO in php and slower ways. But ether way some of you config data will need to be stored outside of a database not matter what such as your database credentials unless you have those hardcoded.
If your really concerned about speed of loading i would suggest setting up a profiler and checking the speed of your options and then go from there.
And external database are more or less api’s that sit and configured on other systems but used by yours.
Node.js doesn’t use magic land either, but with great optimizations it is at least 5 times faster than fastest PHP.[quote=“jgetner, post:15, topic:239137”]
If your really concerned about speed of loading i would suggest setting up a profiler and checking the speed of your options and then go from there.
[/quote]
I know that it will be tax, I don’t need profiler.
Still won’t change anything, it doesn’t matter who owns database, if they run the same speed. It doesn’t matter who owns it.
I don’t know for certain, but I imagine it keeps the values in memory
This would be the trade off from calling in the values each page.
As I posted before, you could try keeping them in the SESSION array.
But I think if a majority of your “thousands” are IP addresses you would be better off storing them in a table as indexed keys and query for them only when you need to.
You can only set dynamic CONSTANT
s if the name of the constants is dynamic. And this still falls under using a database.
good example would be IP ban list. With array something like:
$banned = (“127.0.0.1”, “::1:”, “192.168.1.1”);
It could be edited pretty much every millisecond during DDoS attack.
So it took only ten hours for you to ask a question that makes sense. Good timing.
For this particular task you need not array but a storage. Almost any NoSQL storage would do - Mongo or Redis for example. Besides, for this particular task (given IP ban is not permanent but essentially temporary) good old Memcache could serve as well.
But…
I don’t know how to simply you “settings for the websites”.
Bah again.
If you can’t tell site settings (which are essentially human-editable and gets updated once in a while) from a storage that gets updated pretty much every millisecond (and thus it is only can be done programmatically) - we can do very little to help you. You have to make your mind first.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.