private function generateHeader()
    {
        $this->logger->debug("Generating raw frame header");

        $this->logger->debug("Generated frame 1st byte: " . decbin($this->firstFrameByte) . ", 2nd: " . decbin($this->secondFrameByte));
        $header = chr($this->firstFrameByte) . chr($this->secondFrameByte);

        //Payloads with len. of 7 bits are already handled by secondFrameByte
        if ($this->payloadLengthDiscriminator === 126) {
            $this->logger->debug("Encoding length as 16bit");
            $header .= pack("n", $this->payloadLength);

        } elseif ($this->payloadLengthDiscriminator === 127) {
            $this->logger->debug("Encoding length as 64bit");
            //64 bit support in pack()/unpack() was introduced in 5.6.3, which is too young to require it
            //This method also allows proper 64-bit packets handling on 32-bits systems
            $highMap = 0xffffffff00000000;
            $lowMap = 0x00000000ffffffff;
            $higher = ($this->payloadLength & $highMap) >> 32;
            $lower = $this->payloadLength & $lowMap;
            $header .= pack('NN', $higher, $lower);

        } else {
            $this->logger->debug("Length encoded as 7bit");
        }

        if ($this->secondFrameByte & 128) { //Packet is masked, so attach masking key
            $this->logger->debug("Attaching masking key");
            $header .= ord($this->maskingKey);
        }

        return $header;
    }