473,473 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why are there locale troubles under Windows?

I will report a snippet from http://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/lib...7x(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.

Feb 16 '07 #1
2 3624
On Sat, 17 Feb 2007 00:03:34 +0100, Daniele C.
<le********@users.sourceforge.netwrote:
I will report a snippet from http://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/lib...7x(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.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Feb 17 '07 #2
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.netwrote:
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/lib...7x(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.

Feb 17 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Timothy Smith | last post by:
i'm trying to setlocale() on 4.10, and it appears the python package doesn't support this under 4.10. Python 2.3.3 (#2, Apr 28 2004, 22:48:37) ] on freebsd4 Type "help", "copyright", "credits"...
1
by: Klaus Gr?nb?k | last post by:
Hi all Im from Denmark and we have a few charcters in our alphabet that are not standard ASCII (æåøÆÅØ). I want to be able to print these characters to the console, but for that i need to imbue...
0
by: Manlio Perillo | last post by:
Regards. I have a few questions about locale handling on Windows. The first: why getlocale() returns (None, None) when the locale is 'C'? The second is: why this code fails?: >>> loc, enc...
0
by: R | last post by:
Hi all, I have a simple question about locale and PHP5. I'm using polish characters but I encode them in UTF-8. I was sorting an array with usort($array, 'strcoll'); but I've entred a...
0
by: schaf | last post by:
Hi NG! I have a really suspect problem! Irun the following code on a Windows XP Professional SP2 and every thing works fine: System.Globalization.NumberFormatInfo numberFormatInfo =...
4
by: maxt | last post by:
I am using Windows XP, Tomcat 5.5.17, JRE 1.5.0_08. I am in Australia. For testing localization, my Windows Region is set to English, US. The Tomcat xml's are set to their install defaults. ...
3
by: robert | last post by:
Why can the default locale not be set by its true name? but only by '' ? : PythonWin 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win32. (None, None) Traceback (most recent call last): File...
2
by: Giovanni Bajo | last post by:
Hello, I am trying to find a good way to portably get the output of strftime() and put it onto a dialog (I'm using PyQt, but it doesn't really matter). The problem is that I need to decode the...
2
by: mpalomas | last post by:
Hi C++ folks, I have trouble to open files whose path contains non-ascii characters with std::ifstream. For instance let's say i just have a file which has Japanese characters either in the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.