Ratchet without Symfony session

五迷三道 提交于 2019-12-11 09:45:12

问题


I want to work with ratchet without Symfony session and handle session with php handler between my web application and ratchet. but it doesn't work.

My code for session handling:

Run server : 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();

My app: 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());

Client side :

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!!!';
}

My url for request : localhost/myfile/?name=shahrokh


回答1:


This won't work. From the Ratchet doc:

In order to access your session data in Ratchet, you must also use the same Symfony Session Handler on you website.



来源:https://stackoverflow.com/questions/17811469/ratchet-without-symfony-session

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!