Both of the commenters are right, you need to revisit how you are doing this.
More specifically, the Minecraft protocol uses UDP, which means you need to have access to the raw socket using socket_create
- http://php.net/manual/en/function.socket-create.php
Then you need to build a string
that contains all of the of the required packets correctly, as @Marc B outlined. Then you can write that string to the socket. Note that since UDP is both stateless and has no error correction, you will also have to write retry routines if you get an error back.
What you are currently doing is building data structures in one language (PHP), then trying to write them to a wire protocol (totally different), which is pretty much impossible.
It's certainly possible to do this in PHP, but you have to work at a much lower level than you are now doing, with raw sockets, hex data strings and network error handling. I would suggest you look at other PHP libraries which handle UDP data to see if there is some code you can reuse.
There is some code in the socket_create
page comments that you might be able to use/learn from. In particular, there is a TFTP example which you might be able to modify.
Not a simple answer, but this is non-trivial to do in any language and PHP isn't really designed for this, so there aren't a lot of examples.