PHP new Memcache

Memcache for a live server eg http://www.xyz.com, what must be the connect() function below…? I inserting domain but does not work getting:
Warning: Memcache::connect(): Can’t connect to xyz.com:11211, Connection refused (111) in /var/sites/b/xyz.com/public_html/xyz.php on line 13
Could not connect
well?

<?php

$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect");  

// line 13 used in place of IP the xyz.com

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n<hr />";

?>

$memcache->get($key); //line 19

I connected success to memcache but in this line getting:

Notice: Undefined variable: memcache in /var/sites/b/xyz.com/public_html/v1/xyz.inc.php on line 19

Fatal error: Call to a member function get() on a non-object in /var/sites/b/xyz.com/public_html/v1/xyz.inc.php on line 19

even I have above this line and non give errors:

$memcache->set($key, $result) or die ("Failed to save data at the server");

$memcache->delete($key);

memcache support enabled
Version 3.0.8

tried procedural api but this
$memcache_obj = memcache_connect(‘x.x.y.z’, 11211);

not work inside functions… how do it work? If put inside this then in local function var, can used in another function…?

function yyyy($key) {
$memcache_obj = memcache_connect(‘x.x.y.z’, 11211);

return memcache_get($memcache_obj, $key);
}

I make this observation: // why this???
echomc(); // this give error … if commented and uncomment next line Not error
//echo memcache_get($memcache_obj, ‘var_key’);

Warning: memcache_get() expects parameter 1 to be MemcachePool, null given in /var/sites/b/xyz.com/public_html/xyz.php on line 45

/* procedural API */

/* connect to memcached server */
$memcache_obj = memcache_connect('x.y.z.f', 11211);

/*
set value of item with key 'var_key'
using 0 as flag value, compression is not used
expire time is 30 seconds
*/

memcache_set($memcache_obj, 'var_key', 'some variable', 0, 30);

function echomc() {
echo memcache_get($memcache_obj, 'var_key');
}

echomc();  // this give error ... if commented and uncomment next line Not error
//echo memcache_get($memcache_obj, 'var_key');

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.