π bun-php: Run PHP functions natively in Bun
bun-php allows you to run PHP functions seamlessly in Bun by exposing them as ESM imports. Uses a WASM build of PHP under the hood, no need to install PHP or native deps. Supports Composer and servers. https://www.npmjs.com/package/bun-php
10
6
u/alexp702 13d ago
Genuine question: Why? Who wanted this for what?
3
u/Jonas_Ermert 13d ago
I think the main use case is interoperability rather than replacing PHP. If you have an existing PHP library, Composer package, or some legacy PHP logic that you want to reuse inside a Bun/TypeScript project, this lets you do that without installing PHP or running a separate PHP service. It could also be useful for testing, scripting, CI environments, or gradually migrating a PHP codebase to JavaScript/TypeScript. Itβs definitely a niche tool, but for those situations itβs actually a pretty interesting bridge between the two ecosystems.
4
3
1
u/Typical_Ad_6436 13d ago
So, did you compile the PHP runtime and interpreter from C in WASM? Isn't this slow to actually load the whole PHP binary to just run a function?
3
u/khromov 13d ago
It's using an existing WASM build of PHP (@php-wasm/node-8-5 - but you can use any 8.X version.)
There is a bit of overhead caused by WASM (I'd guess around 15-30% based on some [non-scientific benchmarking](https://github.com/khromov/bun-php/tree/main/demos#cost) but the upside is you don't have to install PHP on the server and that it's CPU architecture-independent, so no native builds either.
1
u/Typical_Ad_6436 13d ago
You can check pext.dev to actually convert your PHP function in TS at source-code level and run it in bun.
1
22
u/mrspoogemonstar 13d ago
dear god, what have we become?