Re: [RFC] Single binary for CLI and FPM
| From: | Marc Henderkes | Date: | Fri, 27 Nov 2026 08:21:24 +0000 |
| Subject: | Re: [RFC] Single binary for CLI and FPM | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-133235@lists.php.net to get a copy of this message | ||
On Wed, 25 Nov 2026 23:09:09 +0000, Matthieu Napoli wrote:
> > Perhaps there's another alternative: libzend.so. [...] In any case, the
> > performance penalty would be something to measure, but I would prefer
> > this solution if it's viable, personally.
>
> I measured it. The closest thing that builds today is
>
--enable-embed=shared: it produces a libphp.so that contains the
> engine, the extensions and the CLI (since #21385). I linked php and
> php-fpm as two tiny executables against it and compared that with
> the regular php executable.
>
> Cold starts on AWS Lambda: same gain as the single binary. That's good.
>
> However runtime performance is not as good. On x86-64, with all variants running interleaved on
> the same host (142 rounds, median difference with the regular executable):
>
> libphp.so libphp.so + -Bsymbolic
> bench.php +5.4% +0.2%
> bench.php (opcache) +3.6% +0.2%
> micro_bench.php +7.7% +0.5%
> micro_bench (opcache) +3.9% +0.6%
> php-parser (opcache) +1.8% +0.0%
>
> The first column is already built with �G�m�ߴ�
> ���6v-fno-semantic-interposition and
> -Wl,-Bsymbolic-functions (the Lambda hosts were all Intel Xeon).
>
> According to Claude, the cause is EG() and
> CG(): in a PIE executable, gcc accesses
> executor_globals directly, in a shared library through the GOT (936
> places in zend_execute.c alone). -Bsymbolic-functions does not cover
> data. -Bsymbolic does: the linker then turns the GOT loads back into
> direct addressing, and the cost is mostly gone.
>
> On arm64 (measured locally) there is no difference with those flags (±0.5%), because gcc goes
> through the GOT for extern data even in a PIE executable there. Without them it costs about 2%.
>
> So in theory it could work, but -Bsymbolic is required (i.e.
> needs larger changes for distribution), and that could be a problem with programs that embed PHP
> like FrankenPHP AFAICT.
>
> In the end I don't think this approach is better than a single binary, correct me if
> I'm wrong.
>
> Matthieu
Hello Matthieu,
those numbers seem a little on the higher side, but are somewhat plausible. However, the majority of
the cost could be absorbed by selectively applying -Bsymbolic to only EG and CG, then the only
caveat being that an embedder of libphp.so<http://libphp.so>
could no longer change libphp's resolution of the symbols. At least frankenphp doesn't
deliberately interpose globals, so it shouldn't be an issue.
But I like the single binary idea much more, in the future eventually being expanded to php
--frankenphp (I've built frankenphp as a Cgo archive abomination before, perhaps a shared
library would be possible).
Marc