我希望在没有Symfony
会话的情况下使用棘轮,并在我的Web应用程序和棘轮之间处理与php
处理程序的会话。但它没有用。
我的会话处理代码:
运行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
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