1

I installed Memcached on centos 7 and according to phpinfo() Memcached 3.0.4 is available. I also checked for Memcached with ps -eaf | grep Memcached and it was ok. But when I try to make an instance of Memcached() in laravel it returns an Error :

"Class 'App\Utils\Memcached' not found"

This is my code :

<?php

namespace App\Utils;

class MemTools {

    private $mem;

    public function __construct() {
        $this->mem = new Memcached();
        $this->mem->addServer('localhost',11211) or die ("Could not connect");
    }
}
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
Payam Roozbahani
  • 1,225
  • 15
  • 27
  • https://stackoverflow.com/a/2659060/1227923 – Alexey Mezenin Feb 06 '18 at 05:54
  • 1
    Possible duplicate of [PHP memcached Fatal error: Class 'Memcache' not found](https://stackoverflow.com/questions/2659035/php-memcached-fatal-error-class-memcache-not-found) – Hiren Gohel Feb 06 '18 at 05:54
  • No it is not a duplicate question. I know memcached and memcache are different. I installed memcached and used memcached. – Payam Roozbahani Feb 06 '18 at 05:58
  • is there any file physically named Memcached?? you could share that file too as it could help others to understand your problem better – Sohel0415 Feb 06 '18 at 06:03
  • @Sohel0415 No i have no any file or class named Memcached. I have only MemTools class. – Payam Roozbahani Feb 06 '18 at 06:05
  • @Sohel0415 but when i make an instance of MemTools in another class, Laravel returns that error. – Payam Roozbahani Feb 06 '18 at 06:08
  • `No i have no any file or class named Memcached.` so what do you expect to create an instance of? You can't just create instances of php extensions out of thin air... –  Feb 06 '18 at 06:12
  • @btl Thanks but what should i do? I used a tutorial for memcached and there was no any class named Memcached. – Payam Roozbahani Feb 06 '18 at 06:21
  • 1
    Set your `config/cache.php` accordingly and use the `Cache` facade or `cache` helper. https://laravel.com/docs/5.5/cache#configuration –  Feb 06 '18 at 06:34
  • @btl you said : so what do you expect to create an instance of? but according to http://php.net/manual/en/memcached.set.php it uses memcached class – Payam Roozbahani Feb 06 '18 at 06:58
  • I'd start with this: http://php.net/manual/en/class.memcached.php –  Feb 06 '18 at 07:02
  • 1
    The memcached class needs to be referenced from the global namespace, so you prefix it with a backslash: `$memcache = new \Memcache;` –  Feb 06 '18 at 07:06

1 Answers1

1

There is no Memcached class in the App\Utils namespace by default.

I'm not sure what you are trying to achieve, but normally you would:

All of this is detailed in the Laravel documentation.

Camilo
  • 6,504
  • 4
  • 39
  • 60