1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP cache

Discussion in 'Other Languages' started by fuge125, Dec 17, 2013.

  1. fuge125

    fuge125 Newbie

    Joined:
    Dec 14, 2013
    Messages:
    13
    Likes Received:
    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?
     
  2. HerpDerpSlerp

    HerpDerpSlerp Power Member

    Joined:
    Mar 19, 2013
    Messages:
    778
    Likes Received:
    623
    Two tables and run a cron once a day updating the table?
     
  3. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    • Thanks Thanks x 1
  4. fuge125

    fuge125 Newbie

    Joined:
    Dec 14, 2013
    Messages:
    13
    Likes Received:
    1
    Can I use Memcached on a reseller hosting account or do I need VPS maybe a dedicated server?
     
  5. Gogol

    Gogol Elite Member

    Joined:
    Sep 10, 2010
    Messages:
    3,062
    Likes Received:
    2,872
    Gender:
    Male
    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)
     
  6. fuge125

    fuge125 Newbie

    Joined:
    Dec 14, 2013
    Messages:
    13
    Likes Received:
    1
    I nvere used Yii until now. I will chek it.
     
  7. tratata

    tratata Newbie

    Joined:
    Jul 26, 2013
    Messages:
    14
    Likes Received:
    5
    You also can use XCache var cache. I like XCache more than Memcached :cool:
     
  8. hip_hop_x

    hip_hop_x Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 27, 2009
    Messages:
    299
    Likes Received:
    61
    Occupation:
    Developer
    Home Page:
    Another cache method written in php is o1db, no other extension/software required, it caches on disk.
     
  9. fuge125

    fuge125 Newbie

    Joined:
    Dec 14, 2013
    Messages:
    13
    Likes Received:
    1
    Thanks for the tips! I will check them.
     
  10. agj32mrgibbits

    agj32mrgibbits Registered Member

    Joined:
    Mar 1, 2008
    Messages:
    73
    Likes Received:
    50
    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.
     
  11. Gogol

    Gogol Elite Member

    Joined:
    Sep 10, 2010
    Messages:
    3,062
    Likes Received:
    2,872
    Gender:
    Male
    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!
     
  12. mypmmail

    mypmmail Junior Member

    Joined:
    Jan 31, 2008
    Messages:
    111
    Likes Received:
    27
    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)
     
  13. Gogol

    Gogol Elite Member

    Joined:
    Sep 10, 2010
    Messages:
    3,062
    Likes Received:
    2,872
    Gender:
    Male
    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.

     
  14. codePerformance

    codePerformance Newbie

    Joined:
    Jan 15, 2014
    Messages:
    18
    Likes Received:
    2
    Occupation:
    web-developer
    Location:
    europe
    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).
     
  15. sephoral

    sephoral Newbie

    Joined:
    Jan 18, 2014
    Messages:
    14
    Likes Received:
    0
    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