17

I realize there are about 10 of these questions out there but none fit me completely.

Steps completed:

  1. Installed memcache
  2. installed php memcache module
  3. updated laravel config to use memcache
  4. Restarted server

php info results:

memcache.allow_failover 1   1
memcache.chunk_size 8192    8192
memcache.default_port   11211   11211
memcache.default_timeout_ms 1000    1000
memcache.hash_function  crc32   crc32
memcache.hash_strategy  standard    standard
memcache.max_failover_attempts  20  20

memcached-tool results:

         accepting_conns           1
               auth_cmds           0
             auth_errors           0
                   bytes           0
              bytes_read          14
           bytes_written        1096
              cas_badval           0
                cas_hits           0
              cas_misses           0
               cmd_flush           0
                 cmd_get           0
                 cmd_set           0
               cmd_touch           0
             conn_yields           0
   connection_structures           6
       crawler_reclaimed           0
        curr_connections           5
              curr_items           0
               decr_hits           0
             decr_misses           0
             delete_hits           0
           delete_misses           0
       evicted_unfetched           0
               evictions           0
       expired_unfetched           0
                get_hits           0
              get_misses           0
              hash_bytes      524288
       hash_is_expanding           0
        hash_power_level          16
               incr_hits           0
             incr_misses           0
                libevent 2.0.21-stable
          limit_maxbytes   268435456
     listen_disabled_num           0
       lrutail_reflocked           0
            malloc_fails           0
                     pid       12022
            pointer_size          64
               reclaimed           0
            reserved_fds          20
           rusage_system    0.043400
             rusage_user    0.065101
                 threads           4
                    time  1421438137
       total_connections           7
             total_items           0
              touch_hits           0
            touch_misses           0
                  uptime        2607
                 version      1.4.21

It is in php -m as "memcache"

However, when i go into php artisan tinker and try to do any caching I get the typical Fatal error: Class 'Memcached' not found in vendor/laravel/framework/src/Illuminate/Cache/MemcachedConnector.php on line 44

TL;DR;

I have confirmed install of memcache through multiple methods. Confirmed the module for php is installed. Still not allowing me to use memcached class.

Bill Garrison
  • 2,226
  • 3
  • 34
  • 75

4 Answers4

23

If you are in a ubuntu environment, try to install Memcached with this:

sudo apt-get install php5-memcached

After that restart your server with

sudo service lighttpd restart

or

sudo service apachectl2 restart

or

sudo service nginx restart

juaniiton1
  • 739
  • 1
  • 5
  • 11
  • this solved my problem of "class memcached not found" in laravel 5.0, thanks! I also added one more line just before restarting apache2 server, "sudo php5enmod memcached" – Jayant Aug 17 '15 at 11:13
  • sudo apt-get install -y php7.2-memcached, in my case. – Randell Sep 04 '19 at 05:24
19

Memcache and Memcached are two different PHP extensions. Memcache is the older deprecated one. Memcached is a much newer and fully supported extension.

Check out http://pecl.php.net/package/memcached

You may need to also install libmemcached https://launchpad.net/libmemcached/+download

Daniel Williams
  • 8,673
  • 4
  • 36
  • 47
  • I actually ended up using http://pecl.php.net/package/memcached and installing it following the instructions in the readme / copying the 'so' file to the modules directory / adding the so file to my php.ini. Thanks for the help....feel pretty dumb – Bill Garrison Jan 16 '15 at 21:18
  • No problem. This exact issue comes up often because the extensions seem to have the exact same name but are entirely different. Also doesn't help that memcache server is referred to both as memcache and memcached interchangeably. – Daniel Williams Jan 16 '15 at 22:13
  • 1
    What is the best way to install these on a mac? I'm getting this error running artisan commands for a laravel app – Connor Leech Mar 20 '18 at 19:45
10
apt-get install php-memcached

Solved the issue for "Class MemCached not found" coming from Laravel.

Nizar B.
  • 3,098
  • 9
  • 38
  • 56
2

In Laravel/Lumen 5.4 just replace the CACHE_DRIVER=file in .env file, the artisan command will work perfectly, But you will not get all the command as same as laravel.

  • use this method especially if you don't need memcached. for me, it was on my development server where i didn't need memcache or any caching solutions. this solved my problem swiftly without having the need to install packages nor modify my apache/php installation. – Christian Noel Jun 28 '19 at 06:10