php - UTF-8 语言环境删除

标签 php locale gentoo

我写了这个测试脚本:

<?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/

相关文章:

javascript - PHP 和 JQuery 照片上传和裁剪问题

regex - bash 运算符 =~ 是否尊重语言环境?

php - 进行多种语言的翻译

javascript - 在 DOM 加载后更改 PHP 变量,更改会反射(reflect)出来吗?

php - 没有被重定向到登录

c++ - 使用 iostream 根据用户的区域设置格式化数字的高效方法?

java - 如何从 ebuild 链接到 Maven 源 jar

Perl Module Net::DNS - 在解析器对象上调用 "tsig"方法会导致错误

linux - 是否有官方每日更新的 Gentoo portage 的 git 存储库?

php - 使用 PDO 传递 %like% 参数的正确方法?