Page 1 of 1
safety of setLocale
Posted: Mon Oct 18, 2004 5:01 am
by jasongr
Can the PHP setLocale () be used to set the locale on a connection-based level, or it only sets it on a wider level, such as thread-level, process-level, or even server-level?
I would like to know the question for Linux and windows separately.
regards
Posted: Mon Oct 18, 2004 5:02 am
by feyd
considering how most php scripts are processed, I'd say it's per page request.
Posted: Mon Oct 18, 2004 8:04 am
by Weirdan
feyd wrote:considering how most php scripts are processed, I'd say it's per page request.
php setlocale is just a wrapper to setlocale defined in Standard C library. Therefore it's platform-dependent. I'd recommend to use the following script to test if certain implementation is thread-safe:
Code: Select all
set_time_limit(0);
$locales = array(
'C',
'POSIX',
'pt_PT.ISO8859-1',
'ru_RU.KOI8-R',
'es-ES',
//... and so forth
// adjust this array for particular system
);
$localeset = setlocale(LC_ALL, $locales[rand(0, count($locales)-1)]);
sleep(20); // wait for operator to run several instances
if(setlocale(LC_ALL, "0") != $localeset) {
echo "<b>Your server isn't thread-safe</b>";
} else {
echo "<b>Your server is thread-safe</b>";
}
run this script in, say, 10 windows and wait. I wouldn't recommend to use setlocale if any of these windows told you that your server wasn't thread-safe.
Posted: Mon Oct 18, 2004 8:10 am
by jasongr
thanks
I will give this a try
and will post my findings