memcache php doubt

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shihabkb
Forum Newbie
Posts: 7
Joined: Wed Jan 19, 2011 12:41 am

memcache php doubt

Post by shihabkb »

Hi,

I am trying to incorporate caching for my restful web services written in php. I am going to use memcache as cache server. I have installed the memcache. I followed the page http://shikii.net/blog/installing-memca ... windows-7/ for the installation.

After installation I am trying to test my memcache installation is successful or not. I write the following code for testing

Code: Select all

    $memcache = new Memcache; // instantiating memcache extension class
    $memcache->connect("127.0.0.1",11211) or die ("Could not connect"); 

    print_r($memcache);
    echo "<br>";
    try {
  $version = $memcache->getVersion();
 echo "Server version: ".$version."<br/>\n";
    } catch (Exception $ex) {
 echo $ex->getMessage();
    }
But the getVersion is not returning any value. I think the connection is successful but I cannot set/get value to memcache. The result of my code is show below

Code: Select all

Memcache Object ( [connection] => Resource id #3 ) 
Server version: 
Can somebody help me?

regards
Shihab
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: memcache php doubt

Post by Darhazer »

$version actually have to be array and you have to print_r it
Try to set a value and then to get it :)
shihabkb
Forum Newbie
Posts: 7
Joined: Wed Jan 19, 2011 12:41 am

Re: memcache php doubt

Post by shihabkb »

Thanks for your reply.

I tried print_r($memcache->getVersion());

But no change... Its printing nothing... any other ways?
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: memcache php doubt

Post by Darhazer »

According to documentation you have to use addServer() and not connect()
what extension/version you are using?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: memcache php doubt

Post by Weirdan »

Darhazer wrote:According to documentation you have to use addServer() and not connect()
For a single memcache server connect() is ok.
Darhazer wrote: $version actually have to be array and you have to print_r it
Api docs says getVersion() returns string: http://us2.php.net/manual/en/memcache.getversion.php
You must have confused Memcache for Memcached.

@shihabkb, set up error reporting and make sure there are no connection errors:

Code: Select all

<?php
error_reporting(-1);
ini_set('display_errors', true);

// your code
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: memcache php doubt

Post by Darhazer »

Weirdan wrote:
Darhazer wrote: $version actually have to be array and you have to print_r it
Api docs says getVersion() returns string: http://us2.php.net/manual/en/memcache.getversion.php
You must have confused Memcache for Memcached.
Indeed :mrgreen:
shihabkb
Forum Newbie
Posts: 7
Joined: Wed Jan 19, 2011 12:41 am

Re: memcache php doubt

Post by shihabkb »

I am using memcached.exe version = 1.2.6.0 and extension (php_memcache.dll) version = 2.2.5.0.

And when I tried with error reporting enabled, I got the following error.

<code>
error_reporting(-1);
ini_set('display_errors', true);
</code>

<code>
Memcache::getversion() [memcache.getversion]: Server 127.0.0.1 (tcp 11211) failed with: Failed reading line from stream (0)
</code>

regards
Shihab
Post Reply