PHAR

· 256 words · 2 minute read

I wonder how simiar PHAR is to Pex. Is PHAR a viable way to build and deploy PHP in the same way that Pex does for Python?

The linked pex is from Twitter’s Pants build system, but is implemented in other places as well. I’ve used it in Please, and it works wonderfully. In short, pex is an executable zip file, the contents of which are all of the python files needed to run the script. I don’t understand all of the inner workings of building a pex, but my naive understanding is that you can continue to concatenate zip archives together, and then throw a shebang at the top, make it executable, and you’re ready to go.

It’s nice for a few reasons.

  • A single file contains all of the source code and dependencies.
  • Multiple adjacent pex’s can have different versions of the same library.
  • Deployment becomes a breeze.
  • If my understanding above is accurate, it’s easy to build incrementally.

That last point is a big deal to me, because I would be interested in incremental PHAR builds in a tool like Please. For example, if I had a monorepo of different source packages and third party packages, could the I update the source file in one package and reuse the pre-build packages that hadn’t changed, both third party and source packages? Is it possible to just concatenate them all together? Or does the whole package need to be rebuilt?

I also wonder about other things, such as security, performance, debuggability, total file size savings…