我写了这个测试脚本:
<?php
ini_set('error_reporting', E_ALL );
putenv('LC_ALL=ru_RU.UTF-8');
putenv('LANG=ru_RU');
putenv('LANGUAGE=ru_RU');
setlocale (LC_ALL, "ru_RU.UTF-8");
for($i=0; $i<7; $i++){
echo setlocale(LC_ALL, 0) . "<br>\n";
sleep(1);
}
?>
有输出:
ru_RU.UTF-8
ru_RU.UTF-8
C
ru_RU.UTF-8
ru_RU.UTF-8
ru_RU.UTF-8
C
为什么语言环境有时会崩溃?如何解决这个问题?
最佳答案
来自 http://php.net/manual/en/function.setlocale.php ...
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 in locale settings while a script is running, though the script itself never called setlocale(). This happens due to other scripts running in different threads of the same process at the same time, changing the process-wide locale using setlocale().
我不是 PHP 专家,但我想一个简单的解决方法是首先使用正确的语言环境启动 PHP。你用 gentoo 标记了这个。如果您使用的是 Gentoo 而不是 Apache 的 mod_php,那么您应该能够使用 www-servers/spawn-fcgi 中的/etc/init.d/spawn-fcgi(我写的)来设置 LC_ALL。有关详细信息,请参阅/etc/conf.d/spawn-fcgi。
关于php - UTF-8 语言环境删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13472815/