在某些时候,服务器不能改变区域
问题描述:
我有一个PHP脚本有时在Apache的错误日志触发怪异的警告问题:在某些时候,服务器不能改变区域
bash: warning: setlocale: LC_ALL: cannot change locale (fr_FR.utf8)
bash: warning: setlocale: LC_ALL: cannot change locale (fr_FR.utf8)
bash: warning: setlocale: LC_ALL: cannot change locale (fr_FR.utf8)
bash: warning: setlocale: LC_ALL: cannot change locale (fr_FR.utf8)
下面的代码生成此警告。 (它用于配置gettext)。
$lang='fr_FR.utf8';
$filename = 'default';
putenv("LC_ALL=$lang");
setlocale(LC_ALL, $lang);
bindtextdomain($filename, './config/locale');
bind_textdomain_codeset($filename, "UTF-8");
textdomain($filename);
奇怪的是,警告并没有系统地出现。 如果我重新启动Apache,它将不会在几分钟内出现(即没有任何警告地提供数百个请求),然后它将逐渐开始出现。
谢谢
答
setlocale
不是线程安全的(见What does thread safe mean in a PHP context?。这就是为什么Zend框架实现自己的语言环境系统。
+0
认为这不会是一个问题,因为我的Apache正在prefork模式下运行? – David 2012-07-18 15:29:36
你读[这](http://php.net/manual/ en/function.setlocale.php#refsect1-function.setlocale-notes)? – RobIII 2012-07-18 15:05:21
是的,我认为这与我无关,因为我的服务器上的Apache运行在prefork模式下 – David 2012-07-18 15:15:35