private function collectPayload()
    {
        if ($this->payloadLength === 0) {
            $this->logger->debug("Skipping payload collection [expected length === 0]");

            return true;
        }

        $this->logger->debug("Trying to collect payload...");
        if (!$this->headersCollected) {
            throw new LogicException("Cannot collect payload before headers!");
        }

        $payloadData = substr($this->buffer, 0, $this->remainingPayloadBytes);
        $payloadDataLen = strlen($payloadData);
        $this->buffer = substr($this->buffer, $payloadDataLen);
        $this->remainingPayloadBytes -= $payloadDataLen;
        $this->payload .= $payloadData;
        $this->logger->debug("Got $payloadDataLen bytes of payload, " . $this->remainingPayloadBytes . " left");

        if ($this->remainingPayloadBytes === 0 && ($this->secondFrameByte & 128)) { //Unmask after full payload is received
            $this->logger->debug("Unmasking payload");
            $this->payload = $this->getMaskedPayload();

            return true;
        }

        return ($this->remainingPayloadBytes === 0);
    }