How to check if memcache or memcached is installed for PHP?

前端 未结 10 708
猫巷女王i
猫巷女王i 2020-12-23 13:47

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

Memcache is a caching daemon designed especiall

10条回答
  •  萌比男神i
    2020-12-23 14:16

    this is my test function that I use to check Memcache on the server

    connect('localhost', 11211) or die ("Could not connect");
    
        $version = $memcache->getVersion();
        echo "Server's version: ".$version."
    \n"; $tmp_object = new stdClass; $tmp_object->str_attr = 'test'; $tmp_object->int_attr = 123; $memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server"); echo "Store data in the cache (data will expire in 10 seconds)
    \n"; $get_result = $memcache->get('key'); echo "Data from the cache:
    \n"; var_dump($get_result); }

    if you see something like this

        Server's version: 1.4.5_4_gaa7839e
        Store data in the cache (data will expire in 10 seconds)
        Data from the cache:
        object(stdClass)#3 (2) { ["str_attr"]=> string(4) "test" ["int_attr"]=> int(123) }
    

    it means that everything is okay

    Cheers!

提交回复
热议问题