Laravel по-русски

Русское сообщество разработки на PHP-фреймворке Laravel.

Ты не вошёл. Вход тут.

#1 09.09.2015 18:07:50

Ошибка 'Class memcached.connector does not exist'

Добрый день.

Пытаюсь использовать Illuminate\Database в NOn Laravel.

Делаю вот так:

<?php
namespace App;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Cache\CacheManager;
use Illuminate\Container\Container; // Only needed for DB
use Illuminate\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;


        $capsule = new Capsule;
	$container = $capsule->getContainer();

	$cache_dir = '/tmp';
	$container['config']['cache.driver'] = 'file';
	$container['config']['cache.path'] = $cache_dir;
	$container['files'] = new Filesystem();

	$capsule->addConnection([
        'driver'    => 'mysql',
            'host'      => '127.0.0.1',
            'database'  => 'rr20',
            'username'  => 'root',
            'password'  => '',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
    ]);


	$capsule->setEventDispatcher(new Dispatcher(new Container));
	$capsule->setCacheManager(new CacheManager($container));
	$capsule->setAsGlobal();
	$capsule->bootEloquent();

Все красиво, все работает.
Только пытаюсь перекинуть все на memcache

 $capsule = new Capsule;
	$container = $capsule->getContainer();
	$container['config']['cache.driver'] = 'memcached';
	$container['config']['cache.servers'] = [['host' => '127.0.0.1', 'port' =>  11211, 'weight' => 100, ]];

	// $cache_dir = '/tmp';
	// $container['config']['cache.driver'] = 'file';
	// $container['config']['cache.path'] = $cache_dir;
	// $container['files'] = new Filesystem();

	$capsule->addConnection([
        'driver'    => 'mysql',
            'host'      => '127.0.0.1',
            'database'  => 'rr20',
            'username'  => 'root',
            'password'  => '',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
    ]);


	$capsule->setEventDispatcher(new Dispatcher(new Container));
	$capsule->setCacheManager(new CacheManager($container));
	$capsule->setAsGlobal();
	$capsule->bootEloquent();

Выбрасывает исключение
PHP Fatal error:  Uncaught exception 'ReflectionException' with message 'Class memcached.connector does not exist' in /srv/sites/public/vendor/illuminate/container/Illuminate/Container/Container.php:501
Stack trace:

Прошу помочь...

Не в сети

#2 15.09.2015 10:29:34

Re: Ошибка 'Class memcached.connector does not exist'

Походу самому отвечать...

<?php

require dirname(dirname(__DIR__)) . '/vendor/autoload.php';
require dirname(__DIR__) . '/config.php';

use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Cache\CacheManager as CacheManager;

$dbc = new DB;

$dbc->addConnection(array(
    'driver'    => 'mysql',
    'host'      => DB_HOST,
    'database'  => DB_NAME,
    'username'  => DB_USER,
    'password'  => DB_PASSWORD,
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
));

# Set the default fetch mode for all queries
$dbc->setFetchMode(PDO::FETCH_CLASS);

# Set up the cache
$container = $dbc->getContainer();

$container['config']['cache.driver'] = 'memcached';
$container['config']['cache.memcached'] = array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100);

$container->offsetGet('config')->offsetSet('cache.driver', 'array');

$cacheManager = new CacheManager($container);

$dbc->setCacheManager($cacheManager);

$dbc->setAsGlobal();
$dbc->bootEloquent();

global $dbc;

Не в сети

Подвал раздела