棘轮Symfony会话返回NULL

时间:2018-07-18 11:20:33

标签: php symfony session ratchet nette

我正在用Ratchet构建一个聊天应用程序,我想添加会话,但是当我在网站上设置会话时,无法将其发送到服务器。它返回NULL。我尝试了很多事情,但没有任何工作。感谢您的帮助。

服务器:

use MyApp\Chat;
use Symfony\Component\HttpFoundation\Session\Storage\Handler;

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

$loop   = React\EventLoop\Factory::create();
$webSock = new React\Socket\Server('127.0.0.1:8080', $loop);

$memcached = new Memcached;
$memcached->addServer('127.0.0.1', 11211);

$webServer = new Ratchet\Server\IoServer(
    new \Ratchet\Http\HttpServer(
        new Ratchet\Session\SessionProvider(
            new Ratchet\WebSocket\WsServer(
                new Ratchet\Wamp\WampServer(
                    new Chat
                )
            ),
            new Handler\MemcachedSessionHandler($memcached)
        )
    ),
    $webSock
);
$loop->run();

在网站上:

$memcache = new \Memcached;
$memcache->addServer('127.0.0.1', 11211);

$storage = new NativeSessionStorage(array(), new MemcachedSessionHandler($memcache));
$session = new Session($storage);
$session->start();

$session->set('name', 'asdf');

聊天类:

public function onPublish(ConnectionInterface $conn, $topic, $event, array $exclude, array $eligible) {
   $topic->broadcast($conn->Session->get("name"));
}

0 个答案:

没有答案