ratchetphp/Ratchet · error · RuntimeException

Serialize PhpHandler:serialize code not written yet, write…

Error message

Serialize PhpHandler:serialize code not written yet, write me!

What it means

This is a deliberate unimplemented-feature sentinel: PhpBinaryHandler::serialize() is a stub that unconditionally throws \RuntimeException because the php binary session serialization scheme (session.serialize_handler=php_binary: keys without delimiters, lengths encoded in raw bytes) was never implemented in this class. It fires for any input whenever session data must be encoded while this handler is the active one — no call pattern can avoid it; only an implementation or a different handler resolves it.

Solutions

  1. Use a different, implemented HandlerInterface implementation such as PhpHandler or WddxHandler for the session's serialize_handler configuration.
  2. Implement serialize() following the php_binary format: for each key write strlen(key) as one byte, the key, then the value encoded per type (bool/int/float/string), as documented in unserialize() and the linked php.net comment.
  3. Guard your application's session setup so php_binary is never selected as the serialization handler.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at src/Ratchet/Session/Serialize/PhpBinaryHandler.php:9 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ratchetphp/Ratchet@e621c6c40b (2026-09-16). Data as JSON: /api/errors/7d5311674341b65d. Report an issue: GitHub.

Appendix: source

Thrown at src/Ratchet/Session/Serialize/PhpBinaryHandler.php:9

<?php
namespace Ratchet\Session\Serialize;

class PhpBinaryHandler implements HandlerInterface {
    /**
     * {@inheritdoc}
     */
    function serialize(array $data) {
        throw new \RuntimeException("Serialize PhpHandler:serialize code not written yet, write me!");
    }

    /**
     * {@inheritdoc}
     * @link http://ca2.php.net/manual/en/function.session-decode.php#108037 Code from this comment on php.net
     */
    public function unserialize($raw) {
        $returnData = array();
        $offset     = 0;

        while ($offset < strlen($raw)) {
            $num     = ord($raw[$offset]);
            $offset += 1;
            $varname = substr($raw, $offset, $num);
            $offset += $num;

            // try to unserialize one piece of data from current offset, ignoring any warnings for trailing data on PHP 8.3+
            // @link https://wiki.php.net/rfc/unserialize_warn_on_trailing_data

View on GitHub (pinned to e621c6c40b)