Class 'Memcached' not found in laravel

廉价感情. 提交于 2019-12-24 01:04:02

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/34196482/class-memcached-not-found-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!