简体   繁体   English

symfony2:尝试从名称空间加载类“ Memcache”

[英]symfony2: Attempted to load class “Memcache” from namespace

I using memcache with symfony2 and ratchet I installed memcache using this command line 我在symfony2和棘轮中使用了内存缓存,并使用此命令行安装了内存缓存

sudo apt-get install php-memcache -y

I edited this lines on php.ini file 我在php.ini文件中编辑了此行

session.save_handler=memcache
session.save_path="localhost:11211"

but when i use this line 但是当我用这条线

$memcache = new Memcache;

I get this error 我得到这个错误

symfony2: Attempted to load class "Memcache" from namespace 

my code socketcommand.php 我的代码socketcommand.php

<?php
namespace check\roomsBundle\Command;
use Ratchet\Session\SessionProvider;
use Symfony\Component\HttpFoundation\Session\Storage\Handler;
use Ratchet\App;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

// Include ratchet libs
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
// Change the namespace according to your bundle
use check\roomsBundle\Sockets\Chat;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler;
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;

class SocketCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this->setName('sockets:start-chat')
            // the short description shown while running "php bin/console list"
            ->setHelp("Starts the chat socket demo")
            // the full command description shown when running the command with
            ->setDescription('Starts the chat socket demo')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln([
            'Chat socket',// A line
            '============',// Another line
            'Starting chat, open your browser.',// Empty line
        ]);
        $memcache = new Memcache;
        $memcache->connect('localhost', 11211);

        $session = new SessionProvider(
            new Chat(new MyApp(), $this->getContainer()),
            new Handler\MemcacheSessionHandler($memcache)
        );

        $server = new App('localhost');
        $server->route('/sessDemo', $session);
        $server->run();
    }

}

my chat.php 我的chat.php

<?php
namespace check\roomsBundle\Sockets;
use tuto\testBundle\Entity\Users;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Ratchet\WebSocket\WsServerInterface;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use Symfony\Component\HttpFoundation\Session\Session;


class Chat extends Controller implements MessageComponentInterface, WsServerInterface
{
    protected $container;
    protected $clients;

    //protected $em;

    //protected $db;
    public function __construct(ContainerInterface $container) {
        $this->clients = new \SplObjectStorage;
        $this->container = $container;


        //$this->em = $em;
        //$this->container = $container;
        //$this->em = $em;
    }

    public function onOpen(ConnectionInterface $conn) {
        $this->clients->attach($conn);

        if (!isset ($conn->Session) || !$conn->Session instanceof Session) {
            throw new \RuntimeException('Session is not defined. Make sure that SessionProvider is executed before FOSUserProvider.');
        }
        try {
            $token      = unserialize($conn->Session->get('_security_main'));
            $user       = $token->getUser();
            $provider   = $this->_container->get('fos_user.user_provider.username');
            $conn->User = $provider->refreshUser($user);
        } catch (Exception $ex) {
            $conn->User = null;
        }
    }

replace this line $memcache = new Memcache; 替换此行$memcache = new Memcache;

with this $memcache = new \\Memcache; $memcache = new \\Memcache;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试从名称空间-Symfony2加载类“ COM” - Attempted to load class “COM” from namespace -Symfony2 Symfony2尝试从全局名称空间加载类。 您是否忘记了“使用”声明? - Symfony2 Attempted to load class from the global namespace. Did you forget a “use” statement? ClassNotFoundException:尝试从......加载类“Mongo”(带有持久性)symfony2 - ClassNotFoundException: Attempted to load class “Mongo” from… (with persist) symfony2 Symfony 2 尝试从命名空间“Ratchet\\Server”加载类“IoServer” - Symfony 2 Attempted to load class "IoServer" from namespace "Ratchet\Server" Symfony 3尝试从名称空间“ DrumLessonBookingApp \\ DrumLessonBookingBundle \\ Repository”中加载类“ LessonRepository” - Symfony 3 Attempted to load class “LessonRepository” from namespace “DrumLessonBookingApp\DrumLessonBookingBundle\Repository” Symfony 4 不在生产环境中构建:尝试从命名空间加载类“WebProfilerBundle” - Symfony 4 do not build in Production: Attempted to load class "WebProfilerBundle" from namespace 尝试从命名空间“Symfony\\WebpackEncoreBundle”加载类“WebpackEncoreBundle”。 您是否忘记了另一个命名空间的“use”语句? - Attempted to load class "WebpackEncoreBundle" from namespace "Symfony\WebpackEncoreBundle". Did you forget a "use" statement for another namespace? Symfony2 + Twig:尝试从全局名称空间调用函数“ replace” - Symfony2 + Twig: Attempted to call function “replace” from the global namespace 尝试从全局命名空间加载类“DOMDocument” - Attempted to load class “DOMDocument” from the global namespace 尝试从名称空间加载类“ PDO” - Attempted to load class “PDO” from namespace
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM