-
Notifications
You must be signed in to change notification settings - Fork 8k
thread-safe and thread-local setlocale()
#20531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Girgias
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Frankly, I'd rather try to push people away from using setlocale() by recommending them to use ICU related functionality rather than relying on the OS locales behaving properly.
| BG(ctype_string) = NULL; | ||
| return ZSTR_CHAR('C'); | ||
| } else if (zend_string_equals_cstr(loc, retval, len)) { | ||
| } else if (zend_string_equals_cstr(loc, ZSTR_VAL(ret_str), ZSTR_LEN(ret_str))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } else if (zend_string_equals_cstr(loc, ZSTR_VAL(ret_str), ZSTR_LEN(ret_str))) { | |
| } else if (zend_string_equals(loc, ret_str)) { |
|
I would also be fine with deprecating |
|
The change over to A softer approach might be changing the documentation to highlight the problems, and preferred solution(s). More broadly, this is a symptom of taking code which - like basically all code written for the last twenty years - assumes it will be executed in a pre-fork environment. FrankenPHP innovations at the frontend (server related stuff) do not require a shared address space, similarly innovation at the backend (ie, workers) also do not require a shared address space. I spent a little bit of time digging into the frankenphp code, and I notice that you have complete control over how threads are created. Here is an area of interesting research for you (this is just an idea): I suggest you go a level down from |
I think that's a great idea regardless, but if php itself never tells you what's wrong, it's unlikely that users would open the documentation. Therefore I believe that
You are generally correct! @withinboredom actually just started a discussion about our approach a few days ago and, as I understand it, a long-term goal is still for Go to provide the async backend for when that becomes a possibility - essentially executing php in Goroutines directly. We could of course hook into all MT-unsafe functions to overwrite them, might even be fairly simple in this case (I'm not very familiar with Go's standard library), but I thought fixing it in php-src would be the better idea, given that it would help mod_php as well. |
It's documented at https://www.php.net/manual/en/function.setlocale.php that the
setlocalephp function is not thread locale (and actually, not thread safe, because the Csetlocalefunction is MT-unsafe). This leads to very unexpected behaviour in FrankenPHP.I would therefore like to propose changing
setlocaleto use POSIXuselocaleinstead.Unfortunately, because
querylocaleis only available on BSD, this adds a lot of string caching logic to let users query for current locales, as I'm not aware of a different way. Perhaps you can give me some pointers to avoid this logic.The logic for windows remains unchanged.
See: php/frankenphp#1941
Given the following PHP code to simulate different FrankenPHP requests:
Currently:
Expected, after proposed implementation: