似乎无法将数据包转储到文件中

Alright, so for this project the language I'm using is PhP.

I'm creating a advance cache system to save CPU cycles in my program. By encoding a chunk once, many CPU cycles can get saved and the results would be a faster server.

if(!isset($this->chunkCache[$index])){
        $pk = new BatchPacket();
        $pk->payload = $payload;
        $pk->encode();
        $pk->isEncoded = true;
        $this->chunkCache[$index] = $pk;
        file_put_contents("cache/" . $this->getName() . "/" . $x . "_" . $z . ".dat", $pk);
    }

So the goal here is to encode a chunk, save it into RAM (So it can be used by other players) then create a .dat file that saves the packet so in the future I can skip the encoding part.

Now my problem is that the files that get generated are empty. I don't know why. What I need is the file to contain the $pk packet. Something that should look like this:

["isEncoded"]=>
bool(true)
["channel"]=>
int(0)
["offset"]=>
int(0)
["buffer"]=>

Any ideas would be appreciated.