views:

1246

answers:

2

How do I test if memcache or memcached (for PHP) is installed on my Apache webserver?

Memcache is a caching daemon designed especially for dynamic web applications to decrease database load by storing objects in memory.

+5  A: 

You can look at phpinfo() or check if any of the functions of memcache is available. Ultimately, check whether the Memcache class exists or not.

e.g.

if(class_exists('Memcache')){
  // Memcache is enabled.
}
thephpdeveloper
Good info, but keep in mind all the <code>class_exists</code> function is telling you is if there's ANY class in the defined include/require hierarchy named Memcache.
Alan Storm
Would any other class name itself "memcache"? does any framework or library do this?
Jenko
@Jeremy I've never seen anything else called memcache, so you're likely safe, especially all you have on the page is class_exists()
Darryl Hein
alternative would be checking the extension version? phpversion('memcache')
thephpdeveloper
+2  A: 

why not use the extension_loaded() function?

jcinacio