没有 Symfony 会话的棘轮 [英] Ratchet without Symfony session
本文介绍了没有 Symfony 会话的棘轮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在没有 Symfony
会话的情况下使用棘轮,并在我的 Web 应用程序和棘轮之间使用 php
处理程序处理会话.但它不起作用.
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.
我的会话处理代码:
运行服务器:session.php`
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();
我的应用:chat.php
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());
客户端:
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
推荐答案
这不起作用.来自 棘轮文档:
为了在 Ratchet 中访问您的会话数据,您还必须使用您网站上的相同 Symfony 会话处理程序.
In order to access your session data in Ratchet, you must also use the same Symfony Session Handler on you website.
这篇关于没有 Symfony 会话的棘轮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文