【问题标题】:Ratchet without Symfony session没有 Symfony 会话的 Ratchet
【发布时间】:2013-07-22 14:21:40
【问题描述】:

我想在没有Symfony 会话的情况下使用棘轮,并在我的 Web 应用程序和棘轮之间使用 php 处理程序处理会话。但它不起作用。

我的会话处理代码:

运行服务器:session.php`

ini_set('session.save_handler', 'memcached' );
ini_set('session.save_path', 'localhost:11211' );

use Ratchet\Server\IoServer;
use Ratchet\WebSocket\WsServer;
use MyApp\Chat;

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

    $server = IoServer::factory(
    new WsServer(
    new Chat()
    )
    , 8080
);

    $server->run();

我的应用:chat.php

public function onOpen(ConnectionInterface $conn) {

        // Store the new connection to send messages to later
        $this->clients->attach($conn);

        session_start();

        echo "New connection! ({$conn->resourceId})\n";
        $conn->send('Hello ' . session_id());

客户端:

ini_set('session.save_handler', 'memcached' );
ini_set('session.save_path', 'localhost:11211' );

session_start();

require __DIR__ . './../server/vendor/autoload.php';

$_SESSION['name'] = $_GET['name'];

if (isset($_SESSION['name'])) {
    var_dump($_SESSION['name']);
} else {
    echo 'Not set!!!';
}

我的请求网址:localhost/myfile/?name=shahrokh

【问题讨论】:

    标签: session websocket session-cookies ratchet


    【解决方案1】:

    这行不通。来自Ratchet doc

    为了在 Ratchet 中访问您的会话数据,您还必须使用 您网站上的相同 Symfony 会话处理程序。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-24
    • 2014-11-07
    • 1970-01-01
    相关资源
    最近更新 更多