ratchetphp/Ratchet · error · RuntimeException
Can not change session name in VirtualProxy
Error message
Can not change session name in VirtualProxy
What it means
VirtualProxyForSymfony7 is the Symfony 7 variant of the proxy with the string-typed setName(string $name): void signature; it unconditionally throws RuntimeException because the session name of a virtual proxy is immutable by design.
Solutions
- Set the desired session name during bootstrap (session_name()/ini) before the Ratchet server and proxy are created.
- Remove runtime setName() calls on the proxied session; treat the session name as immutable for the connection.
- Configure the name through framework/session configuration rather than mutating the proxy.
Example fix
// before
$session->setName('SESSID7'); // proxy -> RuntimeException
// after
// bootstrap, before server start:
session_name('SESSID7'); Defensive patterns
Strategy: type-guard
Validate before calling
if ($session instanceof \Ratchet\Session\Storage\Proxy\VirtualProxyForSymfony7) {
throw new \LogicException('Session name is immutable on the Symfony 7 virtual proxy.');
} Type guard
function canRenameSession($session): bool {
return !$session instanceof \Ratchet\Session\Storage\Proxy\VirtualProxyForSymfony7;
} Try / catch
try {
$session->setName($name);
} catch (\RuntimeException $e) {
// configure session.name at bootstrap/framework config instead
} Prevention
- When migrating to Symfony 7, remove runtime setName() calls on Ratchet session proxies.
- Declare session name in framework configuration (framework.session.name).
- Call session_name() before server startup, never inside connection handlers.
When it happens
Trigger: Calling setName('...') on the Symfony 7 virtual session proxy, directly or via framework/session abstraction layers that mutate the session name at runtime.
Common situations: Symfony 7 apps or bundles calling $session->setName() on the injected session; migration from Symfony 6/5 code that renamed sessions mid-request and now hits the proxy guard.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Can not change session name in VirtualProxy
- Can not change session name in VirtualProxy
- Handler must be instance of SessionHandlerInterface
- Argument #4 ($serializer) expected…
- Unable to parse session serialize handler
AI-assisted analysis of ratchetphp/Ratchet@e621c6c40b (2026-09-16).
Data as JSON: /api/errors/569216ced61b2f64.
Report an issue: GitHub.
Appendix: source
Thrown at src/Ratchet/Session/Storage/Proxy/VirtualProxyForSymfony7.php:58
* {@inheritdoc}
*/
public function setId(string $id): void {
$this->_sessionId = $id;
}
/**
* {@inheritdoc}
*/
public function getName(): string {
return $this->_sessionName;
}
/**
* DO NOT CALL THIS METHOD
* @internal
*/
public function setName(string $name): void {
throw new \RuntimeException("Can not change session name in VirtualProxy");
}
}
View on GitHub (pinned to e621c6c40b)