1

I have installed memcached 1.4.4-14 on my windows systems. I have started the service and everything is in order. Now all I am trying to do is test it using .php which is served using IIS.

So I right a basic index.php page and browse through IIS. I can render the page and general .php works. Its just nothing happens with the memcache. There is so much confusion out there about what pre-requisites I need to install. I can't fathom which ones are essential. The PHP I installed is a new clean install with only the php_memcache.dll extensions dumped in .php.

It is worth noting that in phpinfo I can see no reference to memcache.

Would love some basic assistance.

Here is my example that I am using, I believe it is the standard test for memcache session dump.

session_start();
header("Content-type: text/plain");
$memcache = new Memcache;

$memcache->connect("localhost",11211); # You might need to set "localhost" to "127.0.0.1"5
echo $memcache->get(session_id());

Thank you.

1 Answer 1

1

If you're interested in using compression, please note that, at least for PHP version 5.3.2 and Memcache version 3.0.4, when retrieving a key who's value is a numeric or boolean type, PHP throws a notice of the following:

Message: MemcachePool::get(): Failed to uncompress data

The way around this is to test your variable type before setting or adding it to Memcache, or even cast it as a string.

<?php
$key = 'mc_key';
$value = 12345;
$compress = is_bool($value) || is_int($value) || is_float($value) ? false :             MEMCACHE_COMPRESSED;

$mc= new Memcache;
$mc->connect('localhost', 11211);
$mc->set($key, $value, $compress);

echo $mc->get($key);

//Alternative is to cast the variable
$value = is_scalar($value) ? (string)$value : $value;
$mc->set($key, $value, MEMCACHE_COMPRESSED);
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.