Welcome Guest, Not a member yet? Register   Sign In
Reading from PHP file or Database (which is faster?)
#1

[eluser]RS71[/eluser]
Hey,

I'm making a dynamic portal (shows a different page based on the portal_ID in the URL)

Ex: www.site.com/portal/home/711

I want to check if the portal_ID actually exists. Normally I'd just run a query but depending on the page of the portal I might already have 3 or 4 queries (session query, a couple select queries, etc)

If I have many, many users accessing these portals, and maybe a max of 30-60 portals, would it be a good solution to have an if statement check a config file with a list of all the portals or should I just run yet another query?

Thanks mates!
#2

[eluser]drewbee[/eluser]
Keep it in the database, and use query cache. This way, you are now checking a file for each individual query.

CI serializes the result object and stores it in a file, so that exact same thing is pulled back. Almost all the functions are available that were available in the intial query.
#3

[eluser]TheFuzzy0ne[/eluser]
Generally it's quicker to make a database call, as some data is cached in RAM, and the data is also indexed. The best way to confirm this is to benchmark both. On average, my database queries take about 0.005 seconds. I'd imagine that it would take considerably longer than that to locate a file on the disk, read it, and then search it.
#4

[eluser]drewbee[/eluser]
To iterate further on query cache and file accessing.

Query Cache removes the need to make the actual call to the database - reducing load on the server.

Their is no 'locating or searching' of the query cached file - it knows exactly where it is. Each file only contains the serialized result set of said cached query. Trust me ~ Complex enough queries, especially ones that are called many times with no altercations in the query are far better off being stored elsewhere. This, naturally, only becomes a problem once heavy loads start to hit your DB server though.

For instance, I use query cache for anything along the lines of categories, collection of posts, events etc. Something that will not be continually changing. If I can avoid any calls to the database server, you can believe it will be done Smile
#5

[eluser]RS71[/eluser]
Thanks guys

Please excuse my lack of knowledge on the subject but I'd be using CI's query caching feature yes? How does it differ from MySQL caching feature (which I haven't used as well)

CI caches the query in relation to a controller and function correct? So if I have the same query for two different functions or controllers, I'd have two different caches for the same query correct? Hrm.
#6

[eluser]drewbee[/eluser]
Yes -- CI's query caching feature. I have never used mysql's caching feature either, but that still tells me I would need to at least connect to the database and let the database do the processing.

Correct -- CI caches in relation to the controller + method. It is in the following fashion:

controller+method/md5(query);

Any slight change in the query itself will produce a seperate cache file, for instance with a category example. I have a cache of each and every category as well as the breadcrumbs to that category.




Theme © iAndrew 2016 - Forum software by © MyBB