php 未找到 Laravel Lumen Memcached

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29788552/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:35:02  来源:igfitidea点击:

Laravel Lumen Memcached not found

phplaravelmemcachedlumen

提问by Paul Okeke

Ok, I just started with Lumen and I'm trying to use the Auth, but a call to either Auth::check or any other function of Auth.. leads to the below Error Fatal error: Class 'Memcached' not found in vendor\illuminate\cache\MemcachedConnector.php on line 52. I don't want to use Memcached never used it before.

好的,我刚开始使用 Lumen,我正在尝试使用 Auth,但是调用 Auth::check 或任何其他 Auth 函数会导致以下错误 致命错误:供应商中未找到类“Memcached” \illuminate\cache\MemcachedConnector.php 第 52 行。我不想使用以前从未使用过的 Memcached。

I disabled it in the .envfile and set the CACHE_DRIVERand SESSION_DRIVERto array, but still shows the same error.

我在.env文件中禁用了它并将CACHE_DRIVERSESSION_DRIVER设置为数组,但仍然显示相同的错误。

I decided not to use Auth again and to manually handle my authetication with sessions/tokens, but enabling the MiddleWare StartSession results to the same error.

我决定不再使用 Auth 并使用会话/令牌手动处理我的身份验证,但启用 MiddleWare StartSession 结果会导致相同的错误。

$app->middleware([
 // 'Illuminate\Cookie\Middleware\EncryptCookies',
 // 'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
  'Illuminate\Session\Middleware\StartSession',
 // 'Illuminate\View\Middleware\ShareErrorsFromSession',
 // 'Laravel\Lumen\Http\Middleware\VerifyCsrfToken',
]);

Please I'd be so glad if anyone can really help me out here

如果有人能真正帮助我,我会很高兴

EDIT

编辑

After going A little Deep in the framework I Hard Coded the session driver name in the SessionManagerClass within the method getSessionConfig

在框架中深入一点之后,我SessionManager在方法内的类中硬编码了会话驱动程序名称getSessionConfig

public function getSessionConfig()
{
    $this->setDefaultDriver("cookie");//I added this line
    return $this->app['config']['session'];
}

It works though but not a good way of doing things. There is no config file, i believe all configurations are written in .envfile, but i really don't know why the session_driver and cache_driver is defaulted to memecached even after changing it in the .envand then ran composer dump-autoload... Lumen :(

它虽然有效,但不是一种很好的做事方式。没有配置文件,我相信所有的配置都写在.ENV文件,但我真的不知道为什么session_driver和cache_driver默认为memecached即使在改变之后.ENV然后跑去composer dump-autoload......流明:(

EDITThis is my .envfile

编辑这是我的.env文件

APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomKey!!!

APP_LOCALE=en
APP_FALLBACK_LOCALE=en

DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=array
SESSION_DRIVER=cookie
QUEUE_DRIVER=database

I already have this line uncommented in my bootsrap/app.php

我已经在 bootsrap/app.php 中取消注释了这一行

 Dotenv::load(__DIR__.'/../');

My DataBase configuration works perfectly so the .env file is loaded quite alright.

我的数据库配置工作得很好,所以 .env 文件加载得很好。

采纳答案by Alex Osborn

You may need to restart your server, especially if you're using php artisan serve.

您可能需要重新启动服务器,尤其是在使用php artisan serve.

Lumen doesn't appear to pick up .envchanges per-request.

Lumen 似乎不会.env根据请求进行更改。

I had exactly the same issue - trying to use file cache, but received errors regarding Memcached - restarting the server reloads the .envfile.

我遇到了完全相同的问题 - 尝试使用文件缓存,但收到有关 Memcached 的错误 - 重新启动服务器会重新加载.env文件。

回答by w3spi

I spent 3 hours on this problem today. With the help of the post of demvein this topic, I found the solution. Very simple! I hope it won't affect me later in my development.

我今天在这个问题上花了 3 个小时。在本主题中 demve 的帖子的帮助下,我找到了解决方案。很简单!我希望它不会影响我以后的发展。

Just to it, in the .envfile :

就这样,在.env文件中:

CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=array

Ok, I make an UPDATEbecause I was faced with a new problem about the session. In fact, when you set the previous parameters, your session won't be persistent, like said in the documentation: array - sessions will be stored in a simple PHP array and will not be persisted across requests.

好的,我进行了更新,因为我遇到了有关会话的新问题。事实上,当您设置之前的参数时,您的会话将不会是持久的,就像文档中所说的那样:array - sessions will be stored in a simple PHP array and will not be persisted across requests.

So I have to change it, always in .enva file like that :

所以我必须改变它,总是在这样.env的文件中:

SESSION_DRIVER=cookie

With a var_dump(Session::all());I now can see the whole values of my session

有了一个var_dump(Session::all());我现在可以看到我的会话的全部价值

回答by Manoj Thapliyal

In .env file replace

在 .env 文件中替换

#This line:- 
  CACHE_DRIVER = memcached

#With this:- 
   CACHE_DRIVER = array

回答by davidnknight

Make sure not to get caught out by your .env file not being loaded, which by default it's commented out in Lumen. So if you are specifying a different cache driver in your .env, do the following.

确保不要被未加载的 .env 文件所困扰,默认情况下,它在 Lumen 中被注释掉了。因此,如果您在 .env 中指定不同的缓存驱动程序,请执行以下操作。

Note: If you are using the .env file to configure your application, don't forget to uncomment the Dotenv::load() method in your bootstrap/app.php file.

注意:如果您使用 .env 文件来配置您的应用程序,请不要忘记在 bootstrap/app.php 文件中取消对 Dotenv::load() 方法的注释。

Source: http://lumen.laravel.com/docs/cache

来源:http: //lumen.laravel.com/docs/cache

回答by S.Hossein Asadollahi

in your .envfile, you can also use CACHE_DRIVER=fileinstead of CACHE_DRIVER=memcached

在您的.env文件中,您也可以使用CACHE_DRIVER=file代替CACHE_DRIVER=memcached

回答by Ajay Kumar

This issue resolved when i installed this package so try at least

这个问题在我安装这个包时解决了所以至少尝试

First i tried this and it works fine

首先我试过这个,它工作正常

CACHE_DRIVER = array 

but then thought about what is memcached

但后来想到了什么是 memcached

Then i tried this and it works fine without changing driver memcached

然后我尝试了这个,它在不改变驱动程序的情况下工作正常 memcached

apt-get install php-memcached 

回答by Sajjad Ashraf

In my case i added Add CACHE_DRIVER=arrayin .env file
Then

就我而言,我CACHE_DRIVER=array在 .env 文件中添加了 Add
然后

Dotenv::load(__DIR__.'/../');

in my bootstrap/app.phpand the .envfile started working.

在我bootstrap/app.php.env文件开始工作。

回答by Josh LaMar

For me, the issue was that I used the php-7 branch of homestead repository which does not have PHP memcached ready.

对我来说,问题是我使用了 homestead 存储库的 php-7 分支,它没有准备好 PHP memcached。

回答by demve

I had a similar problem now, I couldn't track it down but my guess is that it has something to do with the fact that the defaults configurations are stored in the vendor/laravel/lumen-framework/configfolder, the DotEnv::$inmutablesetting and the artisan serveserver.

我现在遇到了类似的问题,我无法追踪它,但我猜测它与默认配置存储在vendor/laravel/lumen-framework/config文件夹、DotEnv::$inmutable设置和artisan serve服务器中的事实有关。

The solution that worked for me was:

对我有用的解决方案是:

  1. Add in bootstrap/app.phpthe following:Dotenv::makeMutable(); Dotenv::load(__DIR__.'/../'); Dotenv::makeImmutable();

  2. in the .envfile, set all the configuration to "basic drivers" (array, file) even if you are not going to use them, because you w

  1. 添加bootstrap/app.php以下内容:Dotenv::makeMutable(); Dotenv::load(__DIR__.'/../'); Dotenv::makeImmutable();

  2. .env文件中,即使您不打算使用它们,也将所有配置设置为“基本驱动程序”(数组、文件),因为您需要

回答by Masoud

If you have a new lumen installation, you must rename .env.exampleto .env. So it can read your configurations!

如果您有新的 lumen 安装,则必须重命名.env.example.env. 所以它可以读取你的配置!