php - 拉维尔 5.1 : Class cache does not exist

标签 php laravel caching nginx redis

您好,亲爱的提供者,为许多问题提供了许多答案!

我现在使用 SO 一段时间了(5 年多),尽管主要是被动的。这次我遇到了一个让我彻夜难眠却无法解决的问题。

这就是它的全部内容。我将 Laravel 5.1 与 Redis(缓存和 session )结合使用。遗憾的是,当我切换到 nginx 并升级一些软件包(composer)时,一切都停止了。 Laravel 打印出以下异常:

ReflectionException in Container.php line 737:
Class cache does not exist
in Container.php line 737
at ReflectionClass->__construct('cache') in Container.php line 737
at Container->build('cache', array()) in Container.php line 627
at Container->make('cache', array()) in Application.php line 674
at Application->make('cache') in Container.php line 1159
at Container->offsetGet('cache') in SessionManager.php line 156
at SessionManager->createCacheHandler('redis') in SessionManager.php line 128
at SessionManager->createRedisDriver() in Manager.php line 87
at Manager->createDriver('redis') in Manager.php line 63
at Manager->driver() in SessionServiceProvider.php line 48
at SessionServiceProvider->Illuminate\Session\{closure}(object(Application), array()) in Container.php line 734
at Container->build(object(Closure), array()) in Container.php line 627
at Container->make('session.store', array()) in Application.php line 674
at Application->make('Illuminate\Session\Store') in LittleGateKeeperServiceProvider.php line 39
at LittleGateKeeperServiceProvider->register() in Application.php line 531
at Application->register(object(LittleGateKeeperServiceProvider)) in ProviderRepository.php line 74
at ProviderRepository->load(array('Illuminate\Encryption\EncryptionServiceProvider', 'Illuminate\Foundation\Providers\ArtisanServiceProvider', 'Illuminate\Auth\AuthServiceProvider', 'Illuminate\Broadcasting\BroadcastServiceProvider', 'Illuminate\Bus\BusServiceProvider', 'Illuminate\Cache\CacheServiceProvider', 'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider', 'Illuminate\Routing\ControllerServiceProvider', 'Illuminate\Cookie\CookieServiceProvider', 'Illuminate\Database\DatabaseServiceProvider', 'Illuminate\Filesystem\FilesystemServiceProvider', 'Illuminate\Foundation\Providers\FoundationServiceProvider', 'Illuminate\Hashing\HashServiceProvider', 'Illuminate\Mail\MailServiceProvider', 'Illuminate\Pagination\PaginationServiceProvider', 'Illuminate\Pipeline\PipelineServiceProvider', 'Illuminate\Queue\QueueServiceProvider', 'Illuminate\Redis\RedisServiceProvider', 'App\Providers\PasswordResetServiceProvider', 'Illuminate\Session\SessionServiceProvider', 'Illuminate\Translation\TranslationServiceProvider', 'Illuminate\Validation\ValidationServiceProvider', 'Illuminate\View\ViewServiceProvider', 'Lahaxearnaud\LaravelPushbullet\LaravelPushbulletServiceProvider', 'Spatie\Backup\BackupServiceProvider', 'Collective\Remote\RemoteServiceProvider', 'Vinkla\Pusher\PusherServiceProvider', 'Way\Generators\GeneratorsServiceProvider', 'Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider', 'App\Providers\AppServiceProvider', 'App\Providers\EventServiceProvider', 'App\Providers\RouteServiceProvider', 'Tymon\JWTAuth\Providers\JWTAuthServiceProvider', 'ConnorVG\Transform\TransformServiceProvider', 'Maatwebsite\Excel\ExcelServiceProvider', 'yajra\Datatables\DatatablesServiceProvider', 'Fadion\Bouncy\BouncyServiceProvider', 'Spatie\LittleGateKeeper\LittleGateKeeperServiceProvider')) in Application.php line 507
at Application->registerConfiguredProviders() in RegisterProviders.php line 17
at RegisterProviders->bootstrap(object(Application)) in Application.php line 203
at Application->bootstrapWith(array('Illuminate\Foundation\Bootstrap\DetectEnvironment', 'Illuminate\Foundation\Bootstrap\LoadConfiguration', 'Illuminate\Foundation\Bootstrap\ConfigureLogging', 'Illuminate\Foundation\Bootstrap\HandleExceptions', 'Illuminate\Foundation\Bootstrap\RegisterFacades', 'Illuminate\Foundation\Bootstrap\RegisterProviders', 'Illuminate\Foundation\Bootstrap\BootProviders')) in Kernel.php line 222
at Kernel->bootstrap() in Kernel.php line 117
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54

值得一提的是:我安装了predis,为nginx打开了resty。 奇怪的是,如果我使用文件缓存驱动程序,它运行得很好,没有任何异常。如果我通过 cli ping redis,我会得到正确的“PONG”响应,但我不知道现在该做什么..(除了不使用 redis 驱动程序;-))。

也许值得一提的是,如果我通过 cli 运行 artisan 命令,它会给出不同的错误:

PHP Catchable fatal error:  Argument 2 passed to         Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\Http\Request, null given, called in /var/www/html/*laravel-project*/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php on line 62 and defined in /var/www/html/*laravel-project*/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php on line 99

Catchable fatal error: Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\Http\Request, null given, called in /var/www/html/*laravel-project*/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php on line 62 and defined in /var/www/html/*laravel-project*/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php on line 99

因此,我认为我的 nginx 虚拟主机配置可能有问题(这是服务器设置的主要更改)。虚拟主机看起来像这样:

server {
    listen       80 default_server;
    #listen      [::]:80 default_server ipv6only=on; ## listen for ipv6
    server_name  *MY_SERVER_NAME*;
    root         /sites/*LARAVEL_PROJECT*/public;
    charset utf-8;

    # Elastic search api config
    location /elastic {
        proxy_pass http://localhost:9200;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }


    #auth_basic_user_file /etc/nginx/htpasswd.users;
    # Kibana web access
    location /kibana {
        auth_basic "Restricted Access";
        auth_basic_user_file /etc/nginx/htpasswd.users;
        proxy_pass http://localhost:5601;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    # entry point to the Laravel project
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    access_log /var/log/nginx/laravel-project-access.log;
    error_log  /var/log/nginx/laravel-project-error.log error;

    sendfile off;
    client_max_body_size 100m;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }

    location ~ /\.ht {
        deny all;
    }
}

有什么想法或建议吗?

提前致谢!

最佳答案

就我而言(laravel 5.2),问题出在自定义服务提供程序中,我在 register() 而不是 boot() 函数中声明了自定义响应宏。

将宏移至 boot() 后,错误消失。

在这里找到了解决方案: https://laracasts.com/discuss/channels/laravel/class-cache-does-not-exist-error-when-use-redis-session-file-session-is-fine

关于php - 拉维尔 5.1 : Class cache does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33851821/

相关文章:

PHP 守护进程/工作环境

php/Mysql关联树搜索和条目查询

php - 在保存之前从 Laravel 模型中剥离空属性

javascript - Laravel 中的 x-editable 错误 419

c++ - 由于引用计数器原子递增/递减,shared_ptrs 是否会遇到缓存未命中?

javascript - 将填写好的 html 表单下载为 pdf

java - 在 JAVA 中点击 URL 而不重定向

php - Laravel:将 Eloquent 集合转换为数组而不转换元素

javascript - 当 service worker 加载新页面时出现 ERR_FAILED,为什么?

javascript - BreezeJs - 带参数的 Ajax 调用,无缓存