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);
    }
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);
    }
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 ) ; }
Collects payload from buffer. Masked packets are decoded.

@return bool|null Returns false if payload not yet collected, true if it was collected. Null is returned if
payload cannot be collected yet
@throws LogicException In case of calling before collecting headers
Collects payload from buffer . Masked packets are decoded .