【发布时间】:2016-08-24 03:59:27
【问题描述】:
我正在使用本地内存缓存服务器来存储值。如果我将 Memcache 定义为 Cache 的选定驱动程序,它工作正常。在 config/cache.php 但是,如果我在 laravel 外部使用 memcache,则 memcache 访问比在 Laravel 控制器中使用 Cache::get() 快得多。
我需要在 Memcache 中存储大量数据,并且可以跨系统访问。所以我试图直接使用 memcache,但我收到了以下错误。
[2016-08-23 14:11:19] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Class 'App\Http\Controllers\Memcache' not found in ....
我的代码如下:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Cache;
use stdClass;
use DB;
use Memcache;
class InternalCommunication extends Controller
{
public function update_stock_prices_memcache()
{
echo "\n before the memcache obj creation ".microtime(true);
$memcache = new Memcache();
$memcache->connect('localhost', 11211) or die ("Could not connect");
//$res1 = $memcache->set('key1',"Some value 2");
$res1 = $memcache->get('key1');
.....
要明确一点——memcache 包已安装并且工作正常,因为我可以通过 Cache: 以及直接从 Laravel 安装外部访问 memcache 来使其工作。 感谢我能得到的任何帮助。
【问题讨论】:
-
new \Memcache;? -
是的,试过了。同样的错误:(我使用的是 PHP7,Laravel 5.2,并且我已经安装了 memcached 和 php70-php-pecl-memcache 包。