${$val} = isset($argv[$id + 1]) ? $argv[$id + 1] : false;
    }
}
$obj = new memcachedTools($host, $port);
// get the filename value (if pressent) and allocate to $obj->filename
if (isset($filename) && trim($filename) != '') {
    $obj->filename = trim($filename);
}
switch ($action) {
    case 'backup':
        $obj->getAllKeys();
        $obj->writeKeysToFile();
        echo "Memcached Data has been saved to file :" . $obj->filename;
        break;
    case 'restore':
        $retval = $obj->writeKeysToMemcached();
        if (!$retval) {
            echo "Memcached Data could not be restored: " . $obj->filename . " Not Found\r\n";
        } else {
            echo "Memcached Data has been restore from file: " . $obj->filename . "\r\n";
        }
        break;
    default:
        echo <<<EOF
Example Usage : php m.php -h 127.0.0.1 -p 112112 -op restore
-h : Memcache Host address ( default is 127.0.0.1 )
-p : Memcache Port ( default is 11211 )
-op : Operation is required !! ( available options is : restore , backup )
-f : File name (default is memcacheData.txt)

NB: The -h address can now contain multiple memcache servers in a 'pool' configuration
$host = '127.0.0.1';
$port = '11211';
$allowedArgs = array('-h' => 'host', '-p' => 'port', '-op' => 'action', '-f' => 'file');
foreach ($allowedArgs as $key => $val) {
    $id = array_search($key, $argv);
    if ($id) {
        ${$val} = isset($argv[$id + 1]) ? $argv[$id + 1] : false;
    }
}
$obj = new memcachedTools($host, $port, isset($file) ? $file : 'memcacheData.txt');
switch ($action) {
    case 'backup':
        $obj->getAllKeys();
        $obj->writeKeysToFile();
        echo "Memcached Data has been saved to file :" . $obj->filename;
        break;
    case 'restore':
        $obj->writeKeysToMemcached();
        echo "Memcached Data has been restore from file: " . $obj->filename;
        break;
    default:
        echo <<<EOF
Example Usage : php m.php -h 127.0.0.1 -p 112112 -op restore
-h : Memcache Host address ( default is 127.0.0.1 )
-p : Memcache Port ( default is 11211 )
-op : Operation is required !! ( available options is : restore , backup )
-f : File name (default is memcacheData.txt)
EOF;
        break;
}
exit;