Skip to content
Advertisement

Class ‘Memcached’ not found in laravel

I am trying to run simple code of cache using memcache in my laravel project.

I have added CACHE_DRIVER=memcached in my .env file.

I have created folder of memcache in C drive and added a file memcache.exe in that, and run in cmd by opening it as administrator.

my code in route is:

Route::get('/', function () {
//    return view('welcome');
    Cache::put('k1','created memcached memory!!',1);
    Cache::add('k2','used "add" in memcached!!',2);
    Cache::forever('k3','using forever to create cache',3);
    $k1 = Cache::get('k1','default');
    $k2 = Cache::pull('k2','default');
    $k3 = Cache::pull('k3','default');
    Cache::forget('k1');
    $check = 0;
    if(Cache::has('k1')){
        return $check = 1;
    }
});

when I run this route, i get error as

Class ‘Memcached’ not found

Is there any solution?

EDIT:

When i remove CACHE_DRIVER=memcached and use CACHE_DRIVER=file above code runs fine. What is correct way CACHE_DRIVER=memcached or CACHE_DRIVER=file? I had referred that from video 1

Advertisement

Answer

You need to install the memcached extension to your server.

If you are using linux then

sudo apt-get install php5-memcached

Here is the launchpad link and here’s pecl’s link

Update :

If you are using xampp in windows you should just do this

In your php.ini file just remove the semi colon before this

;extension=php_memcache.dll

to

 extension=php_memcache.dll

and then restart your server

Note :

Don’t forget to restart or stop and start your server after you install this.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement