使用memcached缓存时,Composer报Class ‘memcached’ Not Found错误
1. 运行环境
1). 当前使用的 Laravel 版本?
2). 当前使用的 php/php-fpm 版本?
PHP 版本:8.1.1
php-fpm 版本:没查到
3). 当前系统
Mac MAMP PRO 6.6.1
4). 业务环境
开发环境
5). 相关软件版本
Nginx:1.19.2
Mysql:5。7.34
Memcached:1.4.32
PHP:8.1.1
2. 问题描述?
1、在PHP文件中直接测试memcached缓存,是可以读取的,代码如下:
$memcached->addServer('127.0.0.1', 11211);
$version = $memcached->getVersion();
echo '<pre>';
print_r($version);
echo '</pre>';
$memcached->set('Key1', 'MAMP PRO');
$result = $memcached->get('Key1');
echo $result;
2.在命令行执行 php artisan queue:work 正常(之前不行,后面修改环境变量后可以了)
3.命令行执行 composer dump-autoload 报错
Error
Class "Memcached" not found
at vendor/laravel/framework/src/Illuminate/Cache/MemcachedConnector.php:69
65| * @return \Memcached
66| */
67| protected function createMemcachedInstance($connectionId)
68| {
> 69| return empty($connectionId) ? new Memcached : new Memcached($connectionId);
70| }
71|
72| /**
73| * Set the SASL credentials on the Memcached connection.
+9 vendor frames
10 [internal]:0
Spatie\Permission\PermissionRegistrar::__construct(Object(Illuminate\Cache\CacheManager))
+14 vendor frames
25 [internal]:0
Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Spatie\Permission\PermissionServiceProvider))
3. 您期望得到的结果?
能够使用memcahced缓存
4. 您实际得到的结果?
使用memcahced缓存出现报错。
推荐文章: