PHP-Binaries icon indicating copy to clipboard operation
PHP-Binaries copied to clipboard

One try: Pack pmmp into a single file

Open crazywhalecc opened this issue 1 year ago • 0 comments

I learned PHP seven years ago just to write PocketMine plugins, and now I'm getting ready to try setting up a bedrock server again, and it suddenly occurred to me that it would be possible to apply the static-php-cli I've been maintaining recently to pmmp?

The result is successful but not perfect. Here is a demo:

2023-12-21 22 05 45

pmmp-bin-linux-x86_64.zip

My build steps

  1. Add missing extensions and libraries for static-php-cli. Currently in branch pmmp-experiment.
  2. Download source: bin/spc download --for-extensions=pmmp-chunkutils2,curl,crypto,ctype,gmp,leveldb,mbstring,mbregex,morton,openssl,pmmpthread,sockets,yaml,zip,igbinary,zlib,phar,opcache --with-php=8.2 --debug.
  3. Build micro SAPI with ZTS, fake-cli mode: bin/spc build pmmp-chunkutils2,curl,crypto,ctype,gmp,leveldb,mbstring,mbregex,morton,openssl,pmmpthread,sockets,yaml,zip,igbinary,zlib,phar,opcache --build-cli --build-micro --enable-zts --debug --with-micro-fake-cli.
  4. Download PocketMine-MP.phar.
  5. Glue it: cat buildroot/bin/micro.sfx PocketMine-MP.phar > pmmp.app.
  6. chmod: chmod +x pmmp.app.
  7. Run once to init config and map: ./pmmp.app.
  8. Disable console input: pmmp.yml -> console.input: false.
  9. Run again: ./pmmp.app.

I also entered the game and connected to the server. Currently, it runs normally without any plugins.

Problems I found

  • pmmp console input cannot be used with micro SAPI, because micro SAPI PHP_BINARY is empty, there is no php-cli executable.
  • phar file loading is not working perfectly (usually I use micro with phar needs require_once at the entry of phar).
  • the executable must be named with yyy.xxx (contains dot).
  • Warning message: Debugging assertions are enabled

I also tried to use --build-cli to generate standalone php and conducted a series of experiments on both macOS and Linux. An independent php-cli is currently more stable. But I don't have enough insight into how pmmp works and the stability of standalone version of these patched PHP extensions.

Anyway, I learned a lot of interesting extensions through this project of pmmp, and I am happy to show my experiments.

crazywhalecc avatar Dec 21 '23 14:12 crazywhalecc