Page 1 of 1

memcached ubuntu php doubt

Posted: Sun Jan 23, 2011 11:46 pm
by shihabkb
Hi,

I am trying to install memcached in Ubuntu 10.04. I have followed the instructions from the site http://stevelove.org/2009/09/30/how-to- ... tu-server/ to installation.

After installation I can access memcached thru telnet and I executed stats command. It is working properly. But when I am trying to connect thru php it is not working. Following is my php file.

Code: Select all

<?php
    $memcache = new Memcache(); 
?>
It return the error “
Fatal error: Class 'Memcache' not found in /home/hysanew/web/memcachetest.php on line
5”.

In my php.ini file and memcached.ini I have added “

Code: Select all

extension = memcached.so
”.

But when I restart the apache server it log an error in the error log as “
PHP warning : Module ‘memcached’ already loaded in Unknown on line 0.
Can somebody help me regarding this issue?

Regards
Shihab

Re: memcached ubuntu php doubt

Posted: Mon Jan 24, 2011 1:23 am
by maneetpuri
Hi,

Just check if the php.ini file is updated to have the line extension = memcached.so added in it also the respective .so file for the extension is there in the extensions directory of PHP.

Cheers,

Re: memcached ubuntu php doubt

Posted: Mon Jan 24, 2011 5:39 am
by shihabkb
Thanks for your answer.

when I execute the command locate memcached.so it is not returning any file (ie, it is not finding any thing). But I found that file in the folder /usr/lib/php5/20090626+lfs.

I have libxmpp.so also in the same folder. And when I execute the command locate libxmpp.so it finds it. But memcached is not finding by locate command. Any issue? (I am not familiar with linux)

regards
Shihab

Re: memcached ubuntu php doubt

Posted: Mon Jan 24, 2011 5:58 am
by shihabkb
I did the updatedb and changed the permission for memcached.so. Now locate command returns the path.

But still the
PHP warning : Module ‘memcached’ already loaded in Unknown on line 0
. in the error log and
Fatal error: Class 'Memcache' not found in /home/hysanew/web/memcachetest.php on line
is coming when I am trying to execute the php file.

regards
Shihab

Re: memcached ubuntu php doubt

Posted: Mon Jan 24, 2011 3:47 pm
by Weirdan
There's two different kind of memcache apis available for php: Memcache and Memcached. You're loading the latter and trying to use the former. Here's the API docs for Memcached extension (the one you have): http://us2.php.net/memcached

Re: memcached ubuntu php doubt

Posted: Tue Jan 25, 2011 2:58 am
by shihabkb
Thanks for your valuable answer. I was totally fed-up with this. After getting your answer I tried to install memcache library and made modification in the ini file. Now it is working fine. My following code is working fine.

Code: Select all

<?php
error_reporting(-1);
ini_set('display_errors', true);
    $memcache = new Memcache(); 
    //$memcache->connect("10.1.11.33",11211) or die ("Could not connect"); 
	$memcache->addServer("10.1.11.33",11211, 33);
	echo "version = " . print_r($memcache->getVersion());

	if ( ! extension_loaded('memcache')) {
            throw new Doctrine_Cache_Exception('In order to use Memcache driver, the memcache extension must be loaded.');
    }
?>
And from symfony I used resultcaching. It is also working. I verified by modifying the content in the database and the modified content is not loading in the result. But after the life span the changed content is loading.

Here is the code snippet which I used to load the cache driver in the symfony framwork.

Code: Select all

   public function configureDoctrine(Doctrine_Manager $manager) {
        $servers = array(
            'host' => '10.1.11.33',
            'port' => 11211,
            'persistent' => true
        );
        $cacheDriver = new Doctrine_Cache_Memcache(array(
            'servers' => $servers,
            'compression' => false
            )
        );
        //enable Doctrine cache
        $manager = Doctrine_Manager::getInstance();
        $manager->setAttribute(Doctrine::ATTR_RESULT_CACHE, $cacheDriver);
        $manager->setAttribute(Doctrine::ATTR_RESULT_CACHE_LIFESPAN, 900);
    }
But I have one more issue. When I tried to clear the cache it is giving me the an error
In order to use Memcache driver, the memcache extension must be loaded.
But in the sample code this error is not returning.

Do u have any solutions for this?

regards
Shihab