ratchetphp/Ratchet · error · RuntimeException
Unable to parse session serialize handler
Error message
Unable to parse session serialize handler
What it means
When no $serializer is supplied, SessionProvider tries to infer one from the PHP ini setting session.serialize_handler (e.g. 'php', 'php_serialize', 'wddx') by dynamically instantiating Ratchet\Session\Serialize\{ClassCase}Handler. If no class matching that name exists, the constructor throws RuntimeException, because it cannot safely serialize/unserialize sessions.
Solutions
- Set session.serialize_handler = php_serialize (or 'php') in php.ini before constructing SessionProvider.
- Explicitly pass a serializer: new SessionProvider($app, $handler, [], new \Ratchet\Session\Serialize\PhpSerializeHandler).
- Call ini_set('session.serialize_handler', 'php') at app bootstrap so ini_get returns a supported value.
- Verify with ini_get('session.serialize_handler') which handler the runtime is using and confirm a matching Ratchet\Session\Serialize\*Handler class exists.
Example fix
// before $provider = new SessionProvider($app, $handler); // ini says 'wddx' -> RuntimeException // after $provider = new SessionProvider($app, $handler, [], new \Ratchet\Session\Serialize\PhpSerializeHandler);
Defensive patterns
Strategy: validation
Validate before calling
$handler = ini_get('session.serialize_handler');
$allowed = ['php', 'php_serialize'];
if (!in_array($handler, $allowed, true)) {
ini_set('session.serialize_handler', 'php');
}
$provider = new SessionProvider($app, $handler); Try / catch
try {
$provider = new SessionProvider($app, $handler);
} catch (\RuntimeException $e) {
ini_set('session.serialize_handler', 'php');
$provider = new SessionProvider($app, $sessionHandler);
} Prevention
- Pin session.serialize_handler to 'php' or 'php_serialize' in php.ini and deployment config.
- Pass an explicit serializer instance to avoid ini dependence entirely.
- Check ini_get('session.serialize_handler') during health checks/startup.
- Avoid wddx/php_binary handlers with Ratchet; they have no matching Serialize handler class.
When it happens
Trigger: Constructing SessionProvider without a $serializer while php.ini's session.serialize_handler is set to a value Ratchet has no handler class for (e.g. 'wddx', 'php_binary', or a custom name), or the ini value is empty/unexpected at runtime.
Common situations: Servers with php.ini configured to an exotic serialize handler; hosting environments overriding session.serialize_handler; PHP builds where the wddx extension's handler was relied on but Ratchet has no WddxHandler; CLI vs web SAPI ini differences.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Argument #4 ($serializer) expected…
- Can not change session name in VirtualProxy
- Can not change session name in VirtualProxy
- Can not change session name in VirtualProxy
- Handler must be instance of SessionHandlerInterface
AI-assisted analysis of ratchetphp/Ratchet@e621c6c40b (2026-09-16).
Data as JSON: /api/errors/bc9a09573fa52f8a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Ratchet/Session/SessionProvider.php:64
*/
public function __construct(HttpServerInterface $app, \SessionHandlerInterface $handler, array $options = array(), $serializer = null) {
if ($serializer !== null && !$serializer instanceof HandlerInterface) { // manual type check to support legacy PHP < 7.1
throw new \InvalidArgumentException('Argument #4 ($serializer) expected null|Ratchet\Session\Serialize\HandlerInterface');
}
$this->_app = $app;
$this->_handler = $handler;
$this->_null = new NullSessionHandler;
ini_set('session.auto_start', 0);
ini_set('session.cache_limiter', '');
ini_set('session.use_cookies', 0);
$this->setOptions($options);
if (null === $serializer) {
$serialClass = __NAMESPACE__ . "\\Serialize\\{$this->toClassCase(ini_get('session.serialize_handler'))}Handler"; // awesome/terrible hack, eh?
if (!class_exists($serialClass)) {
throw new \RuntimeException('Unable to parse session serialize handler');
}
$serializer = new $serialClass;
}
$this->_serializer = $serializer;
}
/**
* {@inheritdoc}
*/
#[HackSupportForPHP8] public function onOpen(ConnectionInterface $conn, ?RequestInterface $request = null) { /*
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) { /**/
$sessionName = ini_get('session.name');
$id = array_reduce($request->getHeader('Cookie'), function($accumulator, $cookie) use ($sessionName) {
if ($accumulator) {
return $accumulator;View on GitHub (pinned to e621c6c40b)