0

I have a problem with a PHP script sometimes triggering weird warnings in the Apache error log :

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)

Below is the code generating this warning. (it is used to configure 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);

The weird thing is that the warning does not systematically appear. If I restart Apache, it will not appear for some minutes (i.e. serving hundreds of requests without any warning) and then it will progressively start appearing.

Thank you

David
  • 1,898
  • 2
  • 14
  • 32
  • Did you read [this](http://php.net/manual/en/function.setlocale.php#refsect1-function.setlocale-notes)? – RobIII Jul 18 '12 at 15:05
  • yes. I thought though that this was not relevant to me since Apache on my server is running in prefork mode – David Jul 18 '12 at 15:15

1 Answers1

0

setlocale is not thread safe (See What does thread safe mean in a PHP context?. That's why the Zend Framework implements their own Locale system.

Community
  • 1
  • 1
Ross Smith II
  • 11,799
  • 1
  • 38
  • 43