|  | Posted by Daniele C. on 02/17/07 16:02 
On Feb 17, 10:19 am, OmegaJunior <omegajun...@spamremove.home.nl>wrote:
 > On Sat, 17 Feb 2007 00:03:34 +0100, Daniele C.
 >
 >
 >
 > <legolas...@users.sourceforge.net> wrote:
 > > I will report a snippet fromhttp://php.net/setlocale
 >
 > >> Warning
 >
 > >> The locale information is maintained per process, not per thread. If
 > >> you are running PHP on a multithreaded server api like IIS or Apache on
 > >> Windows you may experience sudden changes of locale settings while a
 > >> script is running although the script itself never called setlocale()
 > >> itself. This happens due to other scripts running in different threads
 > >> of the same process at the same time changing the processwide locale
 > >> using setlocale().
 >
 > > I spent about 2 seconds before thinking: can it really be? I mean, is
 > > there no way to set locale info per thread? And after a brief web
 > > search I came up with this keyword: _configthreadlocale
 >
 > > Read more at
 > >http://msdn2.microsoft.com/en-us/library//26c0tb7x(VS.80).aspx
 > > (beware, this page is very slow or their servers are anyway).
 > > Looks like this function exists since Windows 95 and guess what it
 > > does: it affects the behaviour of the locale functions so that _each
 > > thread will have indipendent locale settings_.
 >
 > > So, I though: WHY? Why does not PHP use such function in the win32
 > > binding?
 >
 > > Let's be clear, I don't think to have found a solution that PHP
 > > developers could not find, but I would like to know why they did not
 > > fix the bad behaviour of PHP's setlocale() function using the
 > > configthreadlocale() win32 function, there must be some reason I
 > > really could not think about up to now.
 >
 > > I really hope somebody can point me to something to read about this
 > > topic (I found pretty nothing up to now) or better directly explain it
 > > to me.
 >
 > > Thank you
 > > --
 > >   Daniele C.
 >
 > How is PHP supposed to react when someone on the server changes the locale
 > settings while services are running? Do you expect the PHP language to
 > retain every possible OS setting in memory? That could be doable, but what
 > if the setting needed to be changed? And PHP keeps running with an
 > outdated setting because it cached it? No. Better to read it from the OS
 > every time it's needed. Yes, that will make it possible for things to
 > change during script execution. And if your scripts are locale-aware, you
 > should already have programmed that possibility into your scripts.
 >
 > You can compare it to the time setting. If the server admin decides to
 > change the time on the server, it may happen in between executions of
 > script. That means the first execution has the old time, while the next
 > has the new time. Is this a problem? Not in most applications. But it is
 > in time-depending ones. And those should already have taken that
 > possibility into account.
 >
 
 You can already change the _process-wide_ (I remark, process wide and
 not relative to the single thread of the client request) locale
 settings using setlocale(), so the current behaviour is even worse
 than what the developer should expect (theorically, mixed locale
 output can happen if a thread changes the locale while another thread
 had previously started and asked for a specific locale through
 setlocale()).
 You say that the developer should take in account such possibility,
 however considering that the OS allows an implementation (using
 _configthreadlocale()) I am asking why in PHP it is not implemented
 (code and data structures, of course) so that things would be done the
 right way?
 And why are you saying that PHP should keep the OS locale settings in
 memory? I don't understand that, PHP would still be querying the OS
 for locales available BUT the behaviour of all the locale functions
 would be bound to the single thread instead. Reading the MSDN page I
 understood that using _configthreadlocale() no particular trickery is
 needed and you can just use the locale POSIX functions as usual.
 Locale settings would be stored per-thread, of course, simple logic
 suggests it, but it would be transparent and I am really sure that the
 memory overhead (I guess less than a few KBs, so irrelevant!) is worth
 having a consistent PHP function behaviour.
 As you brought the example of the time changing issue, I feel like you
 did not understand my question, or otherwise I totally missed out your
 point, in such case please excuse me and better explain me what you
 are saying.
 
 Anyway, thanks for answering! Seems like nobody has the knowledge/will
 to answer.
 
 Regards,
 --
 Daniele C.
 [Back to original message] |