PHP code example of humanmade / wordpress-pecl-memcached-object-cache

1. Go to this page and download the library: Download humanmade/wordpress-pecl-memcached-object-cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

humanmade / wordpress-pecl-memcached-object-cache example snippets


        $m = new Memcached();
        $m->addServer( '127.0.0.1', 11211 );
        $m->set( 'foo', 100 );
        echo $m->get( 'foo' ) . "\n";
        

    global $memcached_servers;
    $memcached_servers = array(
        array(
            '127.0.0.1', // Memcached server IP address
            11211        // Memcached server port
        )
    );
    

    global $memcached_servers;
    $memcached_servers = array(
        array(
            '1.2.3.4',
            11211
        ),
        array(
            '1.2.3.5',
            11211
        )
    );
    

    
    $key   = 'dummy';
    $value = '100';

    $dummy_value = wp_cache_get( $key );

    if ( $value !== $dummy_value ) {
        echo "The dummy value is not in cache. Adding the value now.";
        wp_cache_set( $key, $value );
    } else {
        echo "Value is " . $dummy_value . ". The WordPress Memcached Backend is working!";
    }
    
bash
    yum install php-pecl-memcached
    
bash
        php -a