hall_of_famer — 2013-09-01T09:29:22-04:00 — #1
I never knew this was the true, but now it seems to be a problem. As a software developer, I cannot assume all my client users are on hosting services that enable PECL extensions installation. Since Memcache and Memcached both require installation through PECL, this is becoming a headache. For those of you developing commercial/free softwares, how do you resolve this problem? Is it possible to achieve good caching without Memcache/Memcached? If so, what are the alternatives?
mittineague — 2013-09-01T18:31:08-04:00 — #2
Maybe the PEAR Cache Lite package?
scallioxtx — 2013-09-02T15:50:41-04:00 — #3
There are a lot of options. You can use Memcache, Apc, XCache (windows only), MySQL, a key/value store like MongoDB, Redis, etc, PHP arrays (not as effective as they are gone once the request stops, but within the request they can speed things up), or even flat files.
The most modular thing to do is write a caching mechanism on a higher level, that has "adapters" for different services. Depending on what's available on the server, use a different adapter.
A good example of this is how lithium (li3) does it. See http://lithify.me/docs/lithium/storage/Cache
hall_of_famer — 2013-09-02T16:29:19-04:00 — #4
I thought Memcache and APC are not bundled with PHP and requires PECL installation, while as a software developer you cannot assume users all have Memcache or APC enabled. Unless you are talking about a different Memcache/APC than I know of? Weird...
scallioxtx — 2013-09-03T02:07:42-04:00 — #5
No we're talking about the same thing. What I suggest is checking the server when your app starts and then use a mechanism that is available.
So first check if Memcache is available (using class_exists). If it is available, use it. If not, check if APC is available. If it is, use it. If not, check for the next thing. And so on and so forth.
hall_of_famer — 2013-09-03T15:09:27-04:00 — #6
I see, thanks for your explanation. I guess most shared hosts will not have Memcache, although I wonder how many of them enable APC. What do you mean by MySQL though? Its not a caching system, is it?
asp_funda — 2013-09-03T18:43:03-04:00 — #7
Most of the good ones have one or another, though like hosting it will be a shared resource and not a dedicated instance.
Its an RDBMS but you can use it for caching as well if none of the usual caching engines work. You can create a memory based table to cache data (like you would in an in-memory storage like MongoDB, or Memcached etc), just be sure not to store ton of it as shared hosting accounts have a strict limitation on how much RAM they can juice off. If memory storage is not available in MySQL then you can just go for a regular MyISAM based table and store key-value pairs.