Change `setlocale()` to use the `uselocale()` C function if available on POSIX too
| From: | Marc Henderkes | Date: | Tue, 28 Oct 2025 15:52:26 +0000 |
| Subject: | Change `setlocale()` to use the `uselocale()` C function if available on POSIX too | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-128991@lists.php.net to get a copy of this message | ||
Hello everyone,
We recently noticed that the setlocale function currently uses
setlocale in its C
implementation as well [https://github.com/php/frankenphp/pull/1941], which is a) not multithreading
safe to use and b) when it doesn't crash, leads to overriding the current locale for the entire
process.
For NTS builds with php-fpm this is not an issue, but for FrankenPHP and mod_php, this leads to
unexpected behaviour described here: https://github.com/php/frankenphp/pull/1941#issuecomment-3457137937
On Windows builds, since PHP 7, it is already per-thread, but on POSIX systems it is not.
I would therefore like to get your reactions on whether it would make sense to unify the behaviour
between POSIX systems and Windows and make the setlocale() function thread-safe and
per-thread, rather than per-process.
In case my proposal sees positive reception, I'd like to go ahead and create an RFC. I will
also implement the changes in php-src, I've already done so as a proof of concept.
Thank you for your time,
Marc Henderkes