r/PHP • u/khromov • Aug 30 '26
π 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
22
10
4
1
u/Typical_Ad_6436 Aug 31 '26
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 Aug 31 '26
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 Aug 31 '26
You can check pext.dev to actually convert your PHP function in TS at source-code level and run it in bun.
1
u/Zealousideal_Post994 Sep 02 '26
Why use bun-php instead of @php-wasm directly?
1
u/khromov Sep 02 '26
I'd say mostly if you want the ESM interop + automatic types generation, the package handles the conversion of values between JS and PHP and generates types.
3
1
1
6
u/alexp702 Aug 31 '26
Genuine question: Why? Who wanted this for what?