Load the Session data and store it into a Read-Only Session.

@param \Ratchet\ConnectionInterface $connection
@return void
186605
protected function loadSession(Connection $connection)
    {
        $sessionId = $connection->session = $this->getSessionIdFromCookie($connection);
        
        $session = clone $this->Session;
        $session->setId($sessionId);
        $session->start();
        
        $readonly = (new ReadOnly(config('session.cookie')))->initialize($session->all(), $sessionId);
        WsSession::swap($readonly);
        Session::flush();
        
        unset($session);
    }
177528
public function onConnect($connection)
    {
        $connection->timeout_timerid = Timer::add(10, function () use ($connection) {
            Worker::log("Register auth timeout (".$connection->getRemoteIp()."). See http://wiki.workerman.net/Error4 for detail");
            $connection->close();
        }, null, false);
    }
476982
public function removeConnection(Connection $connection): void
    {
        $socket = $connection->getSocket();

        if ($socket->getResource()) {
            $index = $socket->getResourceId();
        } else {
            $index = array_search($connection, $this->connections);
        }

        if (!$index) {
            $this->logger->warning('Could not remove connection: not found');
        }

        unset($this->connections[$index]);
        unset($this->resources[$index]);

        $this->server->notify(
            Server::EVENT_SOCKET_DISCONNECT,
            [$connection->getSocket(), $connection]
        );
    }
1044625
protected function getWriteStream(ConnectionInterface $connection)
    {
        $write = new WriteStream();
        $this->addLogging($write, $connection);
        return $write;
    }
670106
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->clear($this->_config->get('cache'), $output);
        $this->clear($this->_config->get('session_location'), $output);
    }
764430
public function connection(ConnectionInterface $connection = null)
    {
        deprecationWarning(
            get_called_class() . '::connection() is deprecated. ' .
            'Use setConnection()/getConnection() instead.'
        );
        if ($connection !== null) {
            $this->setConnection($connection);
        }

        return $this->getConnection();
    }
520080
public function setSession(SessionInterface $session)
    {
        if (!is_object($session) || $this->session !== null) {
            return false;
        }
        
        $this->session = $session;
        
        return true;
    }
461428
public function onSlaveClosed(ConnectionInterface $connection)
    {
        if ($this->status === self::STATE_SHUTDOWN) {
            return;
        }

        try {
            $slave = $this->slaves->getByConnection($connection);
        } catch (\Exception $e) {
            // this connection is not registered, so it died during the ProcessSlave constructor.
            $this->output->writeln(
                '<error>Worker permanently closed during PHP-PM bootstrap. Not so cool. ' .
                'Not your fault, please create a ticket at github.com/php-pm/php-pm with ' .
                'the output of `ppm start -vv`.</error>'
            );

            return;
        }

        // remove slave from reload killer pool
        unset($this->slavesToReload[$slave->getPort()]);

        // get status before terminating
        $status = $slave->getStatus();
        $port = $slave->getPort();

        if ($this->output->isVeryVerbose()) {
            $this->output->writeln(sprintf('Worker #%d closed after %d handled requests', $port, $slave->getHandledRequests()));
        }

        // kill slave and remove from pool
        $this->terminateSlave($slave);

        /*
         * If slave is in registered state it died during bootstrap.
         * In this case new instances should only be created:
         * - in debug mode after file change detection via restartSlaves()
         * - in production mode immediately
         */
        if ($status === Slave::REGISTERED) {
            $this->bootstrapFailed($port);
        } else {
            // recreate
            $this->newSlaveInstance($port);
        }
    }
253976
public function run(Connection $connection, $append = false)
    {
        if (!$append) {
            //in the future, resolve key constraints here
            foreach (array_unique($this->dropTables) as $table) {
                $connection->delete($table, [1 => 1], [\PDO::PARAM_INT]);
            }
        }

        foreach ($this->getSortedFixtures() as $fixture) {
            $this->runFixture($connection, $fixture);
        }
    }
886958
private function removeMigration(Connection $connection, int $index): void
    {
        $connection->delete(static::MIGRATIONS_TABLE, [static::MIGRATIONS_COLUMN_ID => $index]);
    }
1266469
public function release(ConnectionInterface $connection)
    {
        $connectionId = $connection->getConnectionId();
        if($this->hasContextConnection($connectionId)) {
            $connection->updateLastTime();
            $connection->setRecv(true);
            $connection->setAutoRelease(true);

            if (App::isCoContext()) {
                $this->releaseToChannel($connection);
            } else {
                $this->releaseToQueue($connection);
            }

            $this->removeContextConnection($connectionId);
        }
    }
228178
public static function setup(Settings $settings, ConnectionInterface $connection = null)
    {
        return static::getInstance($settings)->load($connection);
    }
40916
protected function checkSlave(Connection $connection)
    {
        $paused = 0;

        while (($lag = $this->getLag($connection)) > $this->options['max_lag']) {
            $this->paused = true;
            $for = $this->options['pause_lag'];

            $this->logger->notice('Chunk detected lag of {lag} on {database}, pausing for {for}', [
                'lag'      => $lag,
                'database' => sprintf('%s/%s', $connection->getHost(), $connection->getDatabase()),
                'for'      => $for
            ]);

            usleep($for);
            $paused += $for;

            if ($paused > $this->options['max_pause_lag']) {
                if ($this->options['continue_lag']) {
                    break;
                } else {
                    throw new RuntimeException('Slave lag did not recover after processing chunk. Aborting.');
                }
            }
        }
    }
1298553
private function isTransactionalEvent(ConnectionInterface $connection, $event)
    {
        if ($this->isPrepared($connection) && $this->transactionLevel > 0) {
            return $this->shouldHandle($event);
        }

        return false;
    }
1294344
public function onWorkerConnect($connection)
    {
        $connection->maxSendBufferSize = $this->sendToWorkerBufferSize;
        $connection->authorized = $this->secretKey ? false : true;
    }
870887
private function releaseToChannel(ConnectionInterface $connection)
    {
        $stats     = $this->channel->stats();
        $maxActive = $this->poolConfig->getMaxActive();
        if ($stats['queue_num'] < $maxActive) {
            $this->channel->push($connection);
        }
    }
375138
public function addConnection(ConnectionInterface $connection)
    {
        // TODO: This should be a pool of connections


        if ($connection->isReadable()) {
            $this->readConnection = $connection;
        }

        if ($connection->isWritable()) {
            $this->writeConnection = $connection;
        }
    }