PHP cache

fuge125

Newbie
Joined
Dec 14, 2013
Messages
13
Reaction score
1
Hello,

I want to cache a DB resultset using PHP. I want a webserver global cache I mean I want to init the cache only once a day and not once per request.
What solution should I use?
 
Can I use Memcached on a reseller hosting account or do I need VPS maybe a dedicated server?
 
You can also implement query caching schemes using frameworks. It is much easier to handle as you don't have install any extensions or implement external classes. I use YII for example ( www.yiiframework.com)
 
I nvere used Yii until now. I will chek it.
 
You also can use XCache var cache. I like XCache more than Memcached :cool:
 
Another cache method written in php is o1db, no other extension/software required, it caches on disk.
 
Thanks for the tips! I will check them.
 
If you can't use memcached on shared hosting just dump the results into a file and update them when the file modified date is older than 24 hours.
 
Not a bad method, but what if you have million rows of data? In that case, reading from file will be slower than reading from db!
If you can't use memcached on shared hosting just dump the results into a file and update them when the file modified date is older than 24 hours.
 
Not a bad method, but what if you have million rows of data? In that case, reading from file will be slower than reading from db!

Not really, the database store the data in a file system as well, just that the data format stored is more efficient. :)
And, typically, the database connection has to go through the network layer which is another resource to consume and database has control and transaction file to maintain.
The advantage of database is exactly for this purpose that it provide transaction control and rollback.

The problem with implementing your own is you need to do the maintenance yourself which is a hassle.
Thus, we should always use readily available implementation.

If your data is huge, cache usually has a limit, which mean it store only a portion of the million records that is being accessed frequently. (another reason why a readily available solution is used)
 
Yeah Transaction is a factor. With that, How would you keep index of the data? What if you need to update them? I personally use filesystem only if I have a pretty small site to build, or do not have a database system available ( quite unlikely these days lol). I sometimes use MongoDb exactly for what you said.

Not really, the database store the data in a file system as well, just that the data format stored is more efficient. :)
And, typically, the database connection has to go through the network layer which is another resource to consume and database has control and transaction file to maintain.
The advantage of database is exactly for this purpose that it provide transaction control and rollback.

The problem with implementing your own is you need to do the maintenance yourself which is a hassle.
Thus, we should always use readily available implementation.

If your data is huge, cache usually has a limit, which mean it store only a portion of the million records that is being accessed frequently. (another reason why a readily available solution is used)
 
Hello,

I want to cache a DB resultset using PHP. I want a webserver global cache I mean I want to init the cache only once a day and not once per request.
What solution should I use?
In my opinion APC (Alternative PHP Cache) would be the best and easiest solution for your Use-Case.
If you got root access on your server simply type in:
pecl install APC

For a compact doc google for:
APC documentation PHP


Key Value stores like Redis or Memcached are better but much mroe complex to install, learn and mantain. Use a small solution first and then do an upgrade (if required).
 
I use Redis for a key/value storage and even some more complex storage things. It is really powerful. Thing is you need some experience to install in on your server. But it's not that hard and you'll find lots of tutos out there

Regards
 
Back
Top