{"record":{"id":"3d52ac085991186d","repo":"ratchetphp/Ratchet","slug":"can-not-change-session-name-in-virtualproxy","errorCode":null,"errorMessage":"Can not change session name in VirtualProxy","messagePattern":"Can not change session name in VirtualProxy","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Ratchet/Session/Storage/Proxy/VirtualProxy.php","lineNumber":61,"sourceCode":"     * {@inheritdoc}\n     */\n    public function setId($id) {\n        $this->_sessionId = $id;\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    public function getName() {\n        return $this->_sessionName;\n    }\n\n    /**\n     * DO NOT CALL THIS METHOD\n     * @internal\n     */\n    public function setName($name) {\n        throw new \\RuntimeException(\"Can not change session name in VirtualProxy\");\n    }\n}\n\n}\n","sourceCodeStart":43,"sourceCodeEnd":66,"githubUrl":"https://github.com/ratchetphp/Ratchet/blob/e621c6c40bf684bbbb877102416ad5303d05a9cc/src/Ratchet/Session/Storage/Proxy/VirtualProxy.php#L43-L66","documentation":"Ratchet's VirtualProxy wraps the session for the duration of a request and deliberately freezes the session name; calling setName() on it is forbidden and always throws RuntimeException. The session name must be set on the underlying (real) session storage before the proxy is active, not on the proxy.","triggerScenarios":"Calling setName() (or an API that internally does, such as Symfony session name mutators or Session::setName) on the VirtualProxy instance handed to your WebSocket/app code.","commonSituations":"Application code trying to rename the session cookie mid-request; framework bridges (Symfony session components) calling setName on the injected session object, which happens to be the proxy.","solutions":["Remove the setName() call on the proxied session; set the session name on the real \\SessionHandler or via ini before/at server startup.","Call session_name('...') (and session.save_path etc.) before the Ratchet server starts handling connections.","If using Symfony integration, configure the session name via framework configuration instead of mutating the session at runtime."],"exampleFix":"// before\n$session->setName('MYSESSID'); // $session is the VirtualProxy -> throws\n// after\n// at bootstrap, before the server starts:\nsession_name('MYSESSID');","handlingStrategy":"type-guard","validationCode":"if ($session instanceof \\Ratchet\\Session\\Storage\\Proxy\\VirtualProxy) {\n    throw new \\LogicException('Cannot rename session on the virtual proxy; set session_name() at bootstrap.');\n}","typeGuard":"function isMutableSession($session): bool {\n    return !$session instanceof \\Ratchet\\Session\\Storage\\Proxy\\VirtualProxy;\n}","tryCatchPattern":"try {\n    $session->setName('MYSESSID');\n} catch (\\RuntimeException $e) {\n    // session name is fixed on the proxy; set it at bootstrap instead\n    session_name('MYSESSID');\n}","preventionTips":["Never mutate the session name at request time; set it once before the server starts.","Treat the proxied session as read-only regarding name/metadata.","Audit middleware/bundles for setName() calls on injected sessions."],"tags":["php","session","unsupported-operation","proxy"],"backgroundTag":"unsupported-operation","analyzedSha":"e621c6c40bf684bbbb877102416ad5303d05a9cc","analyzedAt":"2026-09-16T00:13:27.878Z","contentChangedAt":"2026-09-16T00:13:27.878Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}