开发者

Is there any memcached equivalent in php?

开发者 https://www.devze.com 2023-02-12 21:51 出处:网络
In my website , i want to show some data which will be displayed from th开发者_如何转开发e db for the whole day .

In my website , i want to show some data which will be displayed from th开发者_如何转开发e db for the whole day .

For example, if i have a portion like ' Picture of the day', then i will pick a random picture from the db and display them on the page.

So i dont want the query to be executed for every request . so i decided to use memcached to cache query results for a particular time(may be for 24 hrs) ..

All worked in localhost but my hosting provider does not have them.. So i have to use some different concepts to accomplish this.

Is there any equivalent for memcache in php?


You could use a file for caching, and a filemtime() call to see whether the pick needs to be refereshed. Or a database record containing the pick, and the date it was made.

Both methods would work fine performance-wise for this task - memcache sounds like a bit of overkill for it (although it's obviously convenient to use when it's available)


Though APC cache (http://au2.php.net/apc) is not meant for this, it might work for you if it is enabled by your hosting provider.


You should save it as a file. A Cache is not a storage and you should always expect, that a cache gets cleared even if the timeout has not expired yet.

However, you dont need to save the file as (e.g.) "pictoreOfTheDay.jpg". You must have the pictures saved somewhere anyway, so you will only need to save the filename of one is this.


PHP has a memcache extension: http://php.net/manual/en/book.memcache.php


If you're on shared hosting and can't install memcached, I think your only other option is to store it in your database.

  • Save the cached results as a flat file, which would be relatively slow.
  • You could configure your mysql server to run an in memory database to get better performance.
  • Run a sqlite instance.

It all depends on which options are available on your hosting.


It depends what does your hosting provider support.

As a last resort you can always write the content in a file on disk and either open/read/close the file out or use fpassthru() to output the file directly


You can use file cache for this. An example tutorial http://fclose.net/php-file-cache-sinifi

0

精彩评论

暂无评论...
验证码 换一张
取 消