Skip to content

Reconsider ZTS-only builds for 8.6 until upstream PHP has actually decided #1719

Open

Description

@roxblnfk

#1686 switched all 8.6+ images to ZTS and dropped NTS builds entirely. I'd like to ask for this to be reconsidered, or at least softened, before 8.6.0 GA, because it appears to anticipate an upstream decision that hasn't been made yet.

Upstream status, as far as I can find:

  • The only internals discussion is a pre-RFC from July 2026 ("Deprecating NTS and making ZTS the default build mode", https://externals.io/message/131870). It targets NTS removal for PHP 9.0, not 8.6.
  • There is no RFC on wiki.php.net and no vote.
  • In that thread, a core developer explicitly asked for proper benchmarks under different loads (FPM, Apache prefork) before accepting the "negligible overhead" claim, since performance is the main reason two build modes exist. I couldn't find those benchmarks published anywhere.
  • [PHP 8.6] switch the default from NTS to ZTS #1673 mentions being told that no RFC is needed for build changes, but I couldn't find that statement in the public thread. If it exists, a link would help.

#1689 describes the change as "PHP upstream recommended that we switch the images to use ZTS by default". As far as I can tell, that recommendation came from the author of the pre-RFC in #1673, not from a decision of the PHP project: there is no accepted RFC, no vote, and no release-manager statement that I could find. If there is an official upstream statement I've missed, please link it and I'll gladly close this.

Why this matters for these images specifically:

For many users, php:<version>-cli / -fpm is PHP. Switching them to ZTS-only effectively makes ZTS the default for a large share of the ecosystem before upstream has decided to do so. It could also later be cited as evidence in that very RFC ("everyone already runs ZTS"). The images have historically followed upstream defaults (NTS by default, ZTS as an opt-in variant), and I think that is the right policy here too.

There are also practical concerns:

  • NTS is still the upstream default build in 8.6, and it is what essentially every major distribution ships: Debian/Ubuntu, Alpine, Arch, Fedora/RHEL (ZTS is an off-by-default build conditional), FreeBSD ports (ZTS is an off-by-default option), and Homebrew (explicitly no thread-safe build). With remove zts, instead all images are always built as zts (8.6+) #1686, the 8.6 images become the only mainstream PHP source that is ZTS-only, so behavior in containers will diverge from what extensions and benchmarks are usually tested against.
  • Overhead of ZTS for single-threaded CLI/FPM workloads is claimed to be small, but it hasn't been demonstrated with published, reproducible benchmarks.
  • Some extensions and features still don't support ZTS (e.g. --with-mm session handler, some third-party/commercial extensions such as APM agents).

Request, in order of preference:

  1. For 8.6, keep the previous layout: NTS for cli/fpm/apache, with ZTS available as the -zts variant. Revisit when an RFC is accepted upstream (most likely for 9.0, where the question resolves itself).
  2. If that's not acceptable, at least publish -nts variants for 8.6 so users have a supported migration path, and document the change prominently in the image description / release notes.

Thanks for maintaining these images. I'm not against ZTS as such. I'd just like the official images to follow upstream's decision rather than get ahead of it.

Refs: #1673, #1686, #1689, https://externals.io/message/131870

Activity

  1. tianon commented on Nov 19, 2026

    @tianon
    Member

    cc @henderkes 🙇

    FWIW, I've had a paperclip counter help write some benchmarks to chase various PHP threads, including ZTS overhead, and the results can be seen in the actions on https://github.com/infosiftr/php-bench

    From https://github.com/infosiftr/php-bench/actions/runs/43888110981 (the latest report):


    ...

    • What does the thread-safe (zts) build cost? Up to +19%, and only on 5 of 21 workloads -- zts is measurably slower on fib:jit (+19%), fib:opcache (+9%), fib:baseline (+7%) and 2 more, none above +2%. The other 16 are too close to call.

    ...

    • cli and zts are the non-threaded and thread-safe PHP builds. baseline, opcache and jit are the same build run with no bytecode cache, with opcache, and with opcache plus the JIT compiler.

    ...

    CPU: what does the thread-safe (zts) build cost? -- #742

    script variant cli_ms zts_ms who wins
    arrays baseline 37 38 cli 2% faster
    arrays jit 39 40 too close to call
    arrays opcache 40 40 cli 2% faster
    fib baseline 58 62 cli 7% faster
    fib jit 30 35 cli 16% faster
    fib opcache 50 54 cli 8% faster
    hash baseline 3064 3065 too close to call
    hash jit 3066 3068 too close to call
    hash opcache 3067 3067 too close to call
    includes baseline 12 13 too close to call
    includes jit 16 16 too close to call
    includes opcache 15 15 too close to call
    json baseline 200 203 too close to call
    json jit 202 206 too close to call
    json opcache 202 207 too close to call
    regex baseline 59 62 too close to call
    regex jit 61 63 too close to call
    regex opcache 61 63 too close to call
    strings baseline 88 92 too close to call
    strings jit 83 85 too close to call
    strings opcache 91 94 too close to call

    Up to +19%, and only on 5 of 21 workloads -- zts is measurably slower on fib:jit (+19%), fib:opcache (+9%), fib:baseline (+7%) and 2 more, none above +2%. The other 16 are too close to call.

    heads-up: the zts cost itself varies by more than 15 points across PHP versions on fib:jit (8.2: 31%, 8.3: 22%, 8.4: 16%, 8.5: 8%) -- a single number for those hides a per-version story.

  2. henderkes commented on Nov 19, 2026

    @henderkes
    Contributor

    I'd just like the official images to follow upstream's decision rather than get ahead of it.

    The proposal to switch the Docker images ahead of time came from a php internals slack discussion - it didn't come from me. The idea being to get a grasp on what NTS-only features would actually need to be kept (mm session backend, chroot function, hard timeouts, signal handling, timeout handling). Most of these are half-broken that just haven't been removed yet.

    I'm not necessarily against keeping NTS available for now, but I would like to hear the actual issues you're currently running into. 8.6 went into GA as of 2pm yesterday.

    (Edit: The reason this is starting with the Docker images and not elsewhere is simple: the docker extension installer already had full ZTS support. For distributions it would've meant a larger change.)

  3. henderkes commented on Nov 20, 2026

    @henderkes
    Contributor

    cc @henderkes 🙇

    FWIW, I've had a paperclip counter help write some benchmarks to chase various PHP threads, including ZTS overhead, and the results can be seen in the actions on https://github.com/infosiftr/php-bench

    From https://github.com/infosiftr/php-bench/actions/runs/43888110981 (the latest report):

    ...

    • What does the thread-safe (zts) build cost? Up to +19%, and only on 5 of 21 workloads -- zts is measurably slower on fib:jit (+19%), fib:opcache (+9%), fib:baseline (+7%) and 2 more, none above +2%. The other 16 are too close to call.
      [...]

    These numbers look a lot like <= PHP-8.5 values. Are you sure they are from 8.6? There will still be overhead in the worst case scenarios, as the globals move didn't make it in before 8.6 was branched, but it shouldn't be anywhere near +19% in any case, even with recursive TLS reloading and the JIT still emitting a TLS load rather than direct access instruction (also merged in master).

  4. tianon commented on Nov 20, 2026

    @tianon
    Member
  5. henderkes commented on Nov 20, 2026

    @henderkes
    Contributor

    I copied the 8.6-cli dockerfile into a NTS variant and ran your suite:

    https://github.com/henderkes/php-bench/actions/runs/44659928397

    Up to +7%, and only on 10 of 21 workloads -- zts is measurably slower on strings:jit (+7%), fib:jit (+7%), includes:baseline (+5%) and 7 more, none above +4%. 3 came out measurably faster under zts. The other 8 are too close to call.

    But I wouldn't put too much faith on the numbers being faithful due to CI runners unstable nature. <= 5% differences are hard to measure, even on mostly stable local hardware. The jit slowdowns are probably real, but anything other than that should be at <= 2% difference.

    I'll run the numbers later on a stable cloud runner, but it's a 4 core machine so that'll take a while.

  6. roxblnfk commented on Nov 20, 2026

    @roxblnfk
    Author

    Thanks for the context and for running the suite on 8.6.

    I'm not necessarily against keeping NTS available for now, but I would like to hear the actual issues you're currently running into.

    What we have already run into. We maintain Rapira, an application server by the RoadRunner maintainers. Rapira only works with NTS, and we relied on the NTS builds of the official images. With 8.6 those builds are gone, so we had to publish our own: ghcr.io/rapira-rs/php:8.6-nts. For users, this means moving away from the official images to get the build that is still the default in PHP itself.

    What users will run into. The floating tags (latest, 8, fpm, 8-fpm, apache, alpine, …) already point to 8.6, so the change of build mode arrives with a plain docker pull, without any warning. The problems show up at runtime:

    • prebuilt NTS extensions (APM agents, profilers, loaders) won't load;
    • under ZTS, chdir() only changes PHP's virtual CWD, so native code (FFI, libraries used by extensions) may see a different working directory;
    • the features you listed yourself as NTS-only (signal handling, hard timeouts, chroot) are core functionality for long-running workers;
    • by your own 8.6 run, ZTS is measurably slower on 10 of 21 workloads, up to +7%.

    Where the decision was made. Could you clarify which "php internals slack" this was? If it's the PHP Foundation's Slack, I'd point out that the Foundation funds development but doesn't decide the direction of the project. Those decisions go through the internals list and the RFC process. @DanielEScherzer, @mbeccati, as the 8.6 release managers, were you part of that discussion, and do you support switching the official images to ZTS-only? #1689 currently describes this as "PHP upstream recommended…", and users read that as the position of the PHP project.

    Proposal. Since 8.6 is GA now and you're not against keeping NTS available, could the images publish -nts variants for 8.6 (mirroring the previous -zts ones)? Either way, a note in the Docker Hub description (docker-library/docs) would help: right now it doesn't mention anywhere that 8.6 is built as ZTS. The only explanation is the closed #1689, while users of latest/fpm get the change through a regular docker pull.

  7. henderkes commented on Nov 20, 2026

    @henderkes
    Contributor

    What we have already run into. We maintain Rapira, an application server by the RoadRunner maintainers. Rapira only works with NTS, and we relied on the NTS builds of the official images.

    As long as you use the CG/EG/SG/etc macros like php-src instead of relying on direct struct access, it should work perfectly fine with a ZTS build. But yeah, I can see that it may have broken your expected upgrade.

    What users will run into. The floating tags (latest, 8, fpm, 8-fpm, apache, alpine, …) already point to 8.6, so the change of build mode arrives with a plain docker pull, without any warning.

    I think that's the biggest issue, but at least for php-src there's no forward compatibility promise between minor versions. E.g. 8.6 can (and will) have other breaking changes than the ZTS default.

    by your own 8.6 run, ZTS is measurably slower on 10 of 21 workloads, up to +7%.

    Like I said, don't read too much into these. For one, because they're not representative of real world load, second, because the CI runners are very unreliable. :

    My local run came in at an average 1.5% slowdown
    scriptvariantnts_mszts_msoverhead
    arraysbaseline23.9225.06+4.76%
    arraysopcache24.8925.76+3.51%
    arraysjit25.1525.85+2.79%
    fibbaseline32.6633.96+3.98%
    fibopcache29.7731.12+4.53%
    fibjit16.6317.60+5.86%
    hashbaseline2210.972204.28−0.30%
    hashopcache2215.952209.66−0.28%
    hashjit2215.362208.63−0.30%
    includesbaseline6.906.89−0.11%
    includesopcache8.278.51+2.93%
    includesjit8.828.64−1.97%
    jsonbaseline118.74120.48+1.47%
    jsonopcache121.50121.15−0.28%
    jsonjit120.33122.26+1.61%
    regexbaseline36.1036.18+0.24%
    regexopcache35.8835.66−0.60%
    regexjit36.2735.52−2.07%
    stringsbaseline52.5252.95+0.83%
    stringsopcache53.7853.79+0.02%
    stringsjit47.9247.62−0.62%

    Where the decision was made. Could you clarify which "php internals slack" this was? If it's the PHP Foundation's Slack, I'd point out that the Foundation funds development but doesn't decide the direction of the project.

    Yes, the foundation slack, which isn't only used for foundation work, but also has community channels with plenty discussion about all sorts of non-official work. A ZTS switch suggestion doesn't constitute any php foundation involvement. There was no formal "decision".

    Quoting myself from #1673:

    Hello php-docker team,

    I'm currently in the process of creating a RFC to deprecate building the NTS flavour for PHP 8.6 and removing NTS entirely in PHP 9.0. It appears that all maintainers I've been talking to are generally in favour to save on CI and source maintenance.

    @TimWolla suggested I raise this here and see if you're willing to switch the defaults to ZTS already (with a -nts option available, like there is currently -zts).

    Happy to answer all and any questions you have.

    Proposal. Since 8.6 is GA now and you're not against keeping NTS available, could the images publish -nts variants for 8.6 (mirroring the previous -zts ones)?

    I don't see a reason against it. Though it would be helpful if you could actually detail exact breakage that you're encountering if you attempt switching to ZTS. That's the largest reason for why it was even suggested: see what breaks while there's still a way to fix it. If nobody tests until NTS doesn't exist anymore, we'd have no idea until it was too late.

    FYI, I'm absolutely planning on keeping hard-timeouts, maybe even the zend-mm backend. A ZTS-only build doesn't necessitate dropping that functionality, it would just have to restrict it to single-threaded SAPI usage (like CLI, FPM).

  8. roxblnfk commented on Nov 20, 2026

    @roxblnfk
    Author

    Thanks for the detailed reply and the local numbers.

    On #1689, I'd point out an inaccuracy there: it describes the change as "PHP upstream recommended that we switch the images to use ZTS by default". By your account, this came from a discussion in a community channel of the Foundation's Slack, and "there was no formal 'decision'". So there was no upstream recommendation, only a suggestion by some contributors and a pre-RFC that never became an RFC.

    On "see what breaks": the goal makes sense, but changing the default is a poor way to reach it. The opt-in -zts tags existed for years, and they were the way to test ZTS. People whose setup breaks after a docker pull usually have no reason to come here and report it. They just pin 8.5 or move to other images, as we had to. So this is more likely to produce incomplete data than a real picture. Rapira's ZTS compatibility is a separate topic, and this issue is about the default of the official images. As for compatibility between minor versions: this change doesn't come from PHP 8.6. It's not in UPGRADING or in the image description, so users have no way to expect it.

    @tianon, @yosifkit, since there was no formal upstream decision, could 8.6 go back to the previous layout: NTS in cli/fpm/apache, and ZTS as the -zts variant? 8.6.0 was released only yesterday, so a revert now affects far fewer users than it would later, once 8.6 has spread to production through the floating tags. The only consequence we know of is that downstream images that already switched to cli as their ZTS base (for example FrankenPHP in its docker-bake.hcl) would need to switch back to -zts, a one-line change.

    If reverting the default isn't acceptable to you, then at least -nts variants for 8.6, as the original proposal in #1673 already suggested. Either way, we're happy to help with a PR.


    UPD: besides ZTS itself, the 8.6 images come with two more behavior changes that aren't mentioned anywhere:

    1. The images are now built with --disable-zend-signals. This flag used to be only in the -zts variant, while upstream has Zend Signals enabled by default.
    2. ZTS builds on Linux automatically enable the zend max execution timers. As a result, max_execution_time / set_time_limit() now measures wall-clock time (CLOCK_BOOTTIME) instead of CPU time (ITIMER_PROF). Time spent in sleep() or waiting on a database, HTTP or a queue now counts, while before it didn't. The timeout signal is also different: a thread-directed SIGRTMIN instead of SIGPROF.

    To reproduce:

    $ docker run --rm php:8.5-cli php -r 'set_time_limit(2); sleep(4); echo "ok\n";'
    ok
    $ docker run --rm php:8.6-cli php -r 'set_time_limit(2); sleep(4); echo "ok\n";'
    Fatal error: Maximum execution time of 2 seconds exceeded in Command line code on line 1
    

    Both changes make sense for a ZTS build. But for users of latest/fpm, it means that after a regular docker pull, scripts with an explicit time limit that wait on I/O may start failing with a timeout without any change in their code.

  9. henderkes commented on Nov 20, 2026

    @henderkes
    Contributor

    I don't mind your suggestion, but please understand that

    On "see what breaks": the goal makes sense, but changing the default is a poor way to reach it. The opt-in -zts tags existed for years, and they were the way to test ZTS.

    clearly went without great effect. People use the default or get confused when put before a choice, especially one like NTS vs ZTS, where most information google will dig up is a decade old. That default was/is ZTS for FrankenPHP/parallel/Windows*/Apache users and NTS for Unix/RoadRunner/FPM/CLI.

    I don't believe the default switch will/would affect most users in a noticeable way.

  10. rustatian commented on Nov 20, 2026

    @rustatian

    RoadRunner does not depend on PHP thread safety (you can use any PHP, zts or nts).

  11. henderkes commented on Nov 20, 2026

    @henderkes
    Contributor

    Yes, my understanding is that Roadrunner is based off cli, meaning it gets the unix default of non-apache/frankenphp, which is NTS. Generally no SAPI should depend on php being NTS internally (that's what the global accessor macros exist for).

  12. roxblnfk commented on Nov 20, 2026

    @roxblnfk
    Author

    Users do mostly go with the default, which is exactly why changing the default affects them. But NTS for FPM/CLI isn't a leftover from outdated search results. It's the project's current recommendation: windows.php.net says that "NTS builds are for single-threaded use cases, typically PHP running via FastCGI or on the CLI", while TS builds are for PHP loaded as a web server module. Users who need ZTS (FrankenPHP, parallel) already had -zts available.

    This issue isn't about SAPIs. It's about behavior that users of the image get without any change in their code. The example from the UPD above is a plain script: set_time_limit(2); sleep(4); passes on php:8.5-cli and fails with a fatal error on php:8.6-cli, because max_execution_time now measures wall-clock time instead of CPU time.

  13. xepozz commented on Nov 20, 2026

    @xepozz

    Generally no SAPI should depend on php being NTS internally (that's what the global accessor macros exist for).

    Macros are fine (and I don't know why it is even a point), but they do not change how SAPI works (NTS or ZTS or both). Moreover, usually, if SAPI is not written in C/C++, you're using them from a shim layer, because in Rust or Go you can't use them directly.

    That default was/is ZTS for FrankenPHP

    I think that is the reason why these images were so quickly changed to ZTS.

  14. henderkes commented on Nov 20, 2026

    @henderkes
    Contributor

    No, switching the default doesn't directly benefit FrankenPHP. The immediate advantage is deduplication. There's thousands(+++) of build hours wasted every week because two versions of the same engine exist. It incurs extra work for every packager like Remi (RPM, who maintained two partial builds for a long time and still updates the old streams), Shivam (Homebrew/Windows) Michele (Docker extensions), countless others and myself. And, obviously, the Docker team here, who are also volunteering their work.

    If you're asking why it's NTS that should go: they're 99% the same, except that one can handle multiple threads while the other can't.

  15. rustatian commented on Nov 20, 2026

    @rustatian

    While I completely agree that having 1 mode would be great, it doesn't solve the duplication problem in any way. You just made things more complicated for other SAPIs to use official PHP images by breaking them in a way that, for example, I, as a Rapira maintainer, can't use them anymore because they're ZTS-only now. For other people, that change will also very likely introduce surprises in their apps' behavior because of the reasons stated above.
    So, my simple question is: what problem does that action actually solve?

  16. 28 remaining items

  17. smirnov-e commented on Nov 21, 2026

    @smirnov-e

    @tianon why not to drop default at all and keep only explicit ntz/zts variants with explanation that previous default is called -nts now? That way it could be measured without false assumptions.

    Most users nowadays first wait for X.Y.1 or X.Y.2 patches with most critical bugfixes, so appealing to “some brave persons already use zts” is irrelevant.

  18. roxblnfk commented on Nov 21, 2026

    @roxblnfk
    Author

    +1 to @smirnov-e's suggestion. Only explicit -nts/-zts tags with no default remove the magic: the build mode is visible right in a project's Dockerfile, and no future change of the default, in the images or in PHP itself, would catch anyone off guard. That's what we did for our own images: ghcr.io/rapira-rs/php is published only with 8.6-nts and 8.6-zts tags.

    But there are floating tags like latest. IMO, for them it would be safer to point to 8.5 NTS or 8.6-nts than to 8.6 ZTS: whoever pulls latest would get a regular update within NTS, not a change of build mode they didn't know about.

  19. alcohol commented on Nov 21, 2026

    @alcohol

    not a change of build mode they didn't know about.

    But they could have known about it if they did their due diligence, isn't that the whole point here? Rather than raising their pitchforks, this should be a reminder in that regard perhaps.

  20. smirnov-e commented on Nov 21, 2026

    @smirnov-e

    But they could have known about it if they did their due diligence, isn't that the whole point here?

    That means there is no problem to revert current behaviour, right? Doing due diligence must be applied to everyone in everyday basis, not only when it's convenient.

  21. philipwhiuk commented on Nov 21, 2026

    @philipwhiuk

    Isn't the correct thing to do merely to reflect the PHP defaults? While this isn't an official image it's surely Docker's attempt to produce an image reflecting the intended upstream behaviour out the box as close as possible.

    If PHP makes ZTS the default, then the image reflects it and the community decides if they need a legacy NTS image
    If PHP keeps NTS as the default, then the image reflects it and the community decides if they need a ZTS image as well

    PHP could change the default in 9 and remove it in 10 if they wanted to. That would be the reasonable mechanism to make a breaking change.

    Talk of a 1-7% performance being minimal is kind of ridiculous - entire libraries are re-written to benefit from such performance differences. If you advertised PHP 8.6 as "now upto 7% slower" people would call it a blocking regression.

    If the originator of this change is unable to persuade PHP to change the default then surely that's indicative of the state of ZTS.

  22. SerafimArts commented on Nov 21, 2026

    @SerafimArts

    Let’s just define ts and nts explicitly, as @roxblnfk and @smirnov-e suggested. That will resolve absolutely all issues and questions.

  23. henderkes commented on Nov 22, 2026

    @henderkes
    Contributor

    @rustatian

    So my question is: where is that plan?

    Not written down anywhere, but in discussion internally. The process is:

    • fixing current performance penalties | <- near completion, but edge cases still exist
    • unifying behaviour between NTS and ZTS | <- in process, not only championed by myself, see e.g. max_execution_time counts wall time on ZTS builds, CPU time elsewhere php/php-src#25499 and more
    • researching and understanding what NTS-only functionality needs to be included in ZTS builds and how | <- not started yet
    • eventually deprecating certain behaviour with RFCs | <- not started yet
    • RFC to remove -NTS entirely, all builds have one ABI, with some functionality eventually limited to single-threaded SAPIs | <- not started yet

    Or is there an RFC that has already been processed?

    No, a RFC has not been formally submitted, because it's not time for it yet. As I was explained, in my own understanding, changes to the build system do not have to go through the RFC process if they do not incur a userland change.

    What this means is that if ZTS were to keep --with-mm, hard timeouts and other things currently limited to the NTS build, no RFC would be strictly necessary, albeit still a good idea. If (any of) these things were to be removed, they would need to go through individual RFCs.

    The question whether it's worth writing RFCs to remove them depends on user feedback to see how many even rely on that functionality. So far, no mm session backend users have raised their hand. we only had one report relying on hard timeouts (that being by you, rapira maintainers, which wouldn't actually be covered by BC promises in SAPI or internal land anyhow) and none for the other things.

    A few other things have been raised, but they're either broken, or do not actually relate to thread safety. Examples are:

    max_execution_time in NTS is setitimer(ITIMER_PROF) + SIGPROF, which is process-wide. Per-thread timers (timer_create() with SIGEV_THREAD_ID) exist only since PHP 8.3 and only on Linux. It seems to be fixed there (i.e. --enable-zend-max-execution-timers and others), but I can't guarantee it...
    ZTS builds on Linux automatically enable the zend max execution timers. As a result, max_execution_time / set_time_limit() php/php-src#25499 (ITIMER_PROF). Time spent in sleep() or waiting on a database, HTTP or a queue now counts, while before it didn't. The timeout signal is also different: a thread-directed SIGRTMIN instead of SIGPROF.

    This is governed solely by --enable-zend-max-execution-timers. You can disable or enable them no matter the thread safety setting, it's just that ZTS has the sane default. Whatever 8.3 has to do with that anyways, since we're talking about a removal in 9.0. And again, what signal is used or not has never been under any sort of BC umbrella.

    dl() is unsupported (in principle not even needed, given FFI), ABI is incompatible with NTS, and most packages and prebuilt extensions target NTS.

    dl() is again unrelated to thread safety. Its availability depends on the SAPI being compiled. And I don't understand why ABI compatibility is mentioned yet again, because that was once again never under any BC. You can't load a 8.6-NTS extension on 8.5-NTS any more than you can load a 8.6-ZTS extension.

    For the broken one:

    The images are now built with --disable-zend-signals. This flag used to be only in the -zts variant, while upstream has Zend Signals enabled by default.

    Unrelated to NTS and ZTS, governed by --disable-zend-signals. And it doesn't actually govern signal handling, it governs intern signal deferral in PHP during critical sections. It's pretty broken in NTS anyhow and its only use left is in opcache - and it's currently intended to be removed altogether. Your server doesn't rely on the setting at all.

    Let's see to other problems mentioned that do relate to thread safety, but not to PHP's internal thread safety model:

    Hard timeouts
    --with-mm session backend
    fork()
    No isolation: one segfault kills all concurrent requests.
    ... (some third-party/commercial extensions such as APM agents) [... do not support ZTS].
    Engine thread safety doesn't make extension libraries thread-safe

    For the last one I'd actually liked to say that other than the broken and unbundled ext-imap extension, to my knowledge all libraries currently used by PHP and its common extensions are thread safe. And New Relic has ZTS in beta and every other APM is fully ZTS compatible. And that again relates to ABI, like I must have mentioned ten times by now.

    The misconception here is that these relate to thread safety. But they are not. They're governed by whether the SAPI spawns multiple threads and/or reuses them.

    Now on to some of the other things mentioned...

    under ZTS, chdir() only changes PHP's virtual CWD, so native code (FFI, libraries used by extensions) may see a different working directory;

    Write bad code making ungoverned internal assumptions, get bad results.

    the features you listed yourself as NTS-only (signal handling, hard timeouts, chroot) are core functionality for long-running workers;

    I do not recommend anyone to actually use chroot. Its availability is only guaranteed in embed NTS anyhow. I would be shocked if anyone actually allowed that function to be used... and it's not actually related to PHPs internal thread safety again.

    Engine globals are reached via TLS on every access: EG()/CG()/ PG() expand to _tsrm_ls_cache + offset. _tsrm_ls_cache is a __thread variable per DSO, so every extension must call ZEND_TSRMLS_CACHE_UPDATE() or crash, and the JIT emits the same TLS load in generated code.

    That's the PHP 8.6 access and no longer true in 8.7. And again, virtually all extensions are ZTS compatible.

    Talk of a 1-7% performance being minimal is kind of ridiculous - entire libraries are re-written to benefit from such performance differences. If you advertised PHP 8.6 as "now upto 7% slower" people would call it a blocking regression.

    It's not a 1-7% performance loss, it's 0-7% (in 8.6) in very specialised scenarios that do not translate in the same way to real world usage. I wouldn't be making plans to remove NTS if there weren't a way to essentially eliminate the current performance penalties.

    Not to mention, but even if it's 1-2%, that hardly impacts real-world usage. Docker images and system packages all use very conservative compilation options while more aggressive compilation options on new compilers could provide more than 10% extra performance. GCC still defaults to the hybrid VM and Clang just got a 30%ish performance boost in 8.5 thanks to Arnaud. Windows still ships with MSVC instead of Clang builds that I ported which are 70-150% faster. Everyone is fine with that, but not with the current thread safety overhead for one version?


    I do understand everyones frustration here. But the onslaught of (I assume LLM generated, or poorly researched) potential issues mentioned here doesn't help. The switch was done in advance before 8.6 even entered the RC phase. Half the issues mentioned would've happened in 8.6 NTS too because ABI isn't guarded between minor versions. Everyone complaining about the lack of communication may be technically right, but forgets that there's no actual communication channel that changes are about to come outside of... well, what happens in these images, and php internals.

    What also doesn't help are the personal insults or misrepresentations of what happened. And I once again implore every actual PHP user to write their actual issues in userland php down here, so we can at least get something positive out of this thread. If you don't want to do it for us, just do it for yourself and protect yourself from eventually seeing some ancient NTS-only functionality removed in the future, even if you don't follow the RFC process or have no voting rights.


    Sorry to @tianon and @yosifkit for having to deal with this pile of a thread.

    No slop machine has been tickled in the writing of this response. I do not claim correctness on all issues, because it took long enough to write resposes from mostly just memory. I am not a core PHP developer, this does not constitute an official response.

  24. TuzelKO commented on Nov 22, 2026

    @TuzelKO

    @rustatian

    So my question is: where is that plan?

    Not written down anywhere, but in discussion internally. The process is:

    * fixing current performance penalties | <- near completion, but edge cases still exist
    
    * unifying behaviour between NTS and ZTS | <- in process, not only championed by myself, see e.g. [max_execution_time counts wall time on ZTS builds, CPU time elsewhere php/php-src#25499](https://github.com/php/php-src/issues/25499) and more
    
    * researching and understanding what NTS-only functionality needs to be included in ZTS builds and how | <- not started yet
    
    * eventually deprecating certain behaviour with RFCs | <- not started yet
    
    * RFC to remove -NTS entirely, all builds have one ABI, with some functionality eventually limited to single-threaded SAPIs | <- not started yet
    

    Simply put, are you confirming that ZTS is not finished and does not meet the criteria for a drop-in replacement? If so, why is it being pushed as the default?

    Or is there an RFC that has already been processed?

    No, a RFC has not been formally submitted, because it's not time for it yet. As I was explained, in my own understanding, changes to the build system do not have to go through the RFC process if they do not incur a userland change.

    So you confirm that the decision to migrate to ZTS as the "default" was not officially adopted.

    I do understand everyones frustration here. But the onslaught of (I assume LLM generated, or poorly researched) potential issues mentioned here doesn't help.

    You are attempting to dismiss well-founded criticism. People are trying to explain to you that this change disrupts the supply chain, introduces non-obvious container behavior, causes confusion, breaks compatibility, and leads to a performance degradation (regardless of whether it’s 0–7% or 1–2%). You refuse to engage with these arguments, choosing instead to stir up controversy. You even allege that insults were made—insults that never actually occurred. Simply put, you are being manipulative. As a developer using an "official" image, I do not want to have to audit the entire supply chain; when I request such an image, I expect to be certain that it has been built in accordance with upstream recommendations. Forgive me if this "insults" you, but I have better things to do than track every experiment taking place in a Docker library repository. If a given image does not align with upstream recommendations—and if it alters established standards following nothing more than a "Slack discussion" and an RFC draft—then it cannot be called "official"; it should be labeled as "custom."

    This response was prepared using Google Translate, not an LLM.

    P.S. What causes frustration is the refusal to listen to the community’s feedback, coupled with endless attempts to make excuses. If such a reaction has emerged, it’s a clear red flag that something was handled incorrectly. As @Girgias noted—regarding the claim that the reaction wasn’t "strong enough"—it’s worth keeping in mind that this took place in the Docker Library repository, not the upstream project. Hardly anyone ever checks this space; as I mentioned earlier, people have more pressing priorities than verifying the "official" supply chain.

  25. rustatian commented on Nov 22, 2026

    @rustatian

    @henderkes

    Thank you for the detailed explanation 👍🏻

    Honestly speaking, I'm kinda glad that the discussion about removing NTS was at least started, and thank you for doing that 😃 Sorry if my words insulted you or anyone here, my intentions were positive.

    Rapira was ZTS (and our Windows build is ZTS) + NTS (single-threaded) initially, but I switched to NTS only because of the performance problems I had and because no distro actually provides ZTS PHP builds in their packaging system. I don't remember the actual numbers, but that was something around 5-10% (for 8.5). And I'll update it to use ZTS now, since this is the future.

    For me personally, I have all the answers I need. I already created our own images, since this is trivial, and a plan to resurrect ZTS. Since Rapira is 0.x, that situation does not hit me personally in any way, except for 5 minutes of frustration when switching the image 😄.

  26. SerafimArts commented on Nov 22, 2026

    @SerafimArts

    Write bad code making ungoverned internal assumptions, get bad results.

    Could you please tell me how to write good code?

    chdir(__DIR__ , '/path/to');
    FFI::cdef('', __DIR__ . '/path/to/library.dll'); 
    // library.dll loads /path/to/dependency.dll from "chdir"
    // via Library Loading API (This is the behavior of any OS)
    

    Just for the record, I should mention that I wrote about this unfixable ZTS bug 6 years ago (https://bugs.php.net/bug.php?id=79439), and it is precisely this issue that led to the inclusion of that note in the documentation (php/doc-en#121).

    Please provide an example of the good code how to specify the directory from which a library should load its dependencies when using a ZTS build.

  27. smirnov-e commented on Nov 22, 2026

    @smirnov-e

    @henderkes

    depends on user feedback to see how many even rely on that functionality

    The right place to get feedback is your own FrankenPHP community, not everyone else. For starters change max_executiuon_time behavior to NTS for FrankenPHP users and collect feedback any time necessary.

    but forgets that there's no actual communication channel

    Then it was pretty much stupid to try gather feedback here. You have plenty FrankenPHP users to test on, without damaging other's reputation.

    I do understand everyones frustration here.

    Compare your behavior with nicolas-grekas php/php-src#25499

    • he went through real discussion how to fix behavior differences issue
    • you decided to underhandedly break everyone else except FrankenPHP

    has never been under any sort of BC umbrella.

    Try reading documentation, it clearly says On non Windows systems, the maximum execution time is not affected by system calls, stream operations etc.. This default change must be reflected in PHP release notes, not dug up in Dockerfile's diffs.

    And I don't understand why ABI compatibility is mentioned yet again

    Because extensions are part of ecosystem and, for example, for us absence of New Relic is enough to say No to ZTS.

    And New Relic has ZTS in beta

    Let me remind you that ZTS support was once removed 4 years ago.
    Reasons:

    • Enabling Zend Thread Safety (ZTS) was a massive undertaking and It was an extra-large effort src
    • not enough clients to make this support commercially viable

    Timeline

    • April 21, 2021 — marked ZTS as deprecated (was available since beginning)
    • August 23, 2021 — ZTS build removed. Reason: not enough clients to spend time on it.
    • March 2, 2022 — PHP Agent 9.19.0.309: Last release with ZTS support.
    • March 20, 2024 — request to reintroduce support.
    • May 19, 2026 — announced a beta ZTS-enabled agent for FrankenPHP Classic mode.
    • November 22, 2026 — no publicly available builds yet, zero news for over 1 month.
      Looks like they doesn't have enough clients again and ZTS build may be dropped any time again.

    What also doesn't help are the personal insults or misrepresentations of what happened.

    Then stop insulting others:

    • Write bad code making ungoverned internal assumptions, get bad results.
    • But the onslaught of (I assume LLM generated, or poorly researched) potential issues.

    since we're talking about a removal in 9.0

    Without accepted RFC such claims are obvious lies. Stop spewing LLM generated slop.

    Half the issues mentioned would've happened in 8.6 NTS

    List them, please, point by point. Maybe I overlooked something, but I don't see any.

    The immediate advantage is deduplication. There's thousands(+++) of build hours wasted every week because two versions of the same engine exist

    As of now at least 2 PHP applications servers build their own NTS images and much more people will build them in private due to security team concerns.
    You may claim deduplication goal as achieved ))

    get something positive out of this thread

    We know that «Official Docker Images for PHP» are no longer trustworthy and reliable.

  28. henderkes commented on Nov 22, 2026

    @henderkes
    Contributor

    Write bad code making ungoverned internal assumptions, get bad results.

    Could you please tell me how to write good code?

    chdir(__DIR__ , '/path/to');
    FFI::cdef('', __DIR__ . '/path/to/library.dll'); 
    // library.dll loads /path/to/dependency.dll from "chdir"
    // via Library Loading API (This is the behavior of any OS)
    

    Just for the record, I should mention that I wrote about this unfixable ZTS bug 6 years ago (https://bugs.php.net/bug.php?id=79439), and it is precisely this issue that led to the inclusion of that note in the documentation (php/doc-en#121).

    Please provide an example of the good code how to specify the directory from which a library should load its dependencies when using a ZTS build.

    I'll give you the benefit of the doubt for being serious about this, so I'll try to answer the question before leaving this thread for good, since clearly not much productive has happened here other than from @rustatian.

    For one, even if it isn't what you'd like to hear, PHP makes no promises to the regards of how stdlib methods function internally. Just because a method shares a libc function name doesn't mean that it actually calls the libc function, so chdir() followed by FFI loading a shared library was never promised behaviour. Not that a real chdir would resolve the loaded libraries dependencies against the CWD either, as far as I know.

    Second of all, it's not impossible to solve this not-a-bug. Unix lets processes and libraries define a search callback for loading of shared libraries that we could hook, resolve against the current threads id, and get the cwd from there. https://linux.die.net/man/7/rtld-audit
    Windows likewise has LoadLibraryFlagsEx or whatever it was called that let you pass paths to resolve against.

    Whether it's worth it? Certainly not to me, but feel free to create a PR. It wouldn't count as a bugfix, I mean it's not even functionality currently present in NTS, so only 8.7, but if it's important to you, feel more than welcome to.

    However, using FFI, be it in NTS or ZTS, is almost exclusively a bad idea either way. It's nearly impossible to actually make it safe with exception handling and vm bailout logic as is.

    If you really want functionality to load shared libraries resolved against cwd in ZTS builds today, you can also write a little helper that (recursively) checks the library you want to load for dependencies and builds the correct load-order.

  29. Yoskaldyr commented on Nov 22, 2026

    @Yoskaldyr

    However, using FFI, be it in NTS or ZTS, is almost exclusively a bad idea either way.

    I guess someone forgot to tell the PHP developers that adding FFI support to PHP was almost exclusively a bad idea.

    Perhaps we should just remove FFI from PHP instead of fixing compatibility issues?

    P.S. The more you explain why users shouldn't rely on existing PHP functionality, the better you demonstrate why they shouldn't rely on these Docker images either.

  30. SerafimArts commented on Nov 22, 2026

    @SerafimArts

    To begin with, I was branded a bad developer ("Write bad code making ungoverned internal assumptions, get bad results") - my qualifications were called into question, and I was told that, instead of just using a simple chdir, I should write something like this (and fix "ZTS feature" using FFI): https://github.com/php-ffi/work-directory/blob/master/src/Driver/WindowsThreadSafeDriver.php

    Then I was advised to drop FFI entirely, simply because "It's nearly impossible to actually make it safe with exception handling and vm bailout logic as is" (though why would anyone even try to make something safe when it’s meant to be low-level, efficient, and inherently unsafe?) - and all without offering any alternatives.

    ...

    Thanks, I understand your arguments. I think we can end the conversation here =)

    Honestly, it might be easier to just give up on PHP altogether - after all, it has "unsafe exceptions".

  31. NathanFreeman commented on Nov 23, 2026

    @NathanFreeman

    As a Swoole maintainer, I would like to share a practical architectural limitation we encountered while adapting to ZTS. In SWOOLE_PROCESS mode, the master process's event loop relies heavily on the multi-reactor threading mechanism to dispatch I/O events. Constrained by the current thread-safety mechanisms of ZTS, and to ensure runtime stability, we are forced to restrict reactor_num to 1 in the master process.
    While this does not affect the fundamental operation of Swoole, it is indeed a functional compromise for users who rely on the multi-reactor architecture to handle high-concurrency connections. This is also a major reason why the official Swoole Docker images currently continue to recommend the NTS version by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions