区域设置会更改每个其他页面加载

In one of our web apps the user can select preferred language, so we need to dynamically set locale per user. Basically:

function i18n_date($format, $date, $locale) {
    setlocale(LC_TIME, $locale);
    return strftime($format, $date);
}

The problem is that every other page load, the locale is changed to the default, between setlocale() and strftime(). According to the PHP docs this should be expected from "multithreaded server API like IIS or Apache on Windows", but our server Apache build is non threaded:

Server version: Apache/2.2.17 (Ubuntu)
Server built:   Nov  3 2011 02:13:53
Server's Module Magic Number: 20051115:25
Server loaded:  APR 1.4.2, APR-Util 1.3.9
Compiled using: APR 1.4.2, APR-Util 1.3.9
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="/var/run/apache2/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"

So then why is this happening?

setlocale() is not persistent, you need to set it everytime you need it.

If locales is not persistent, then use something that is PERSISTENT (SESSION rings any bells???).

When the user selects his Locale, save it into the $_SESSION associative array.

Then everytime you load a page, first check whether the variable exists. If it does, then set down the locale else ask for it.

if (isset($_SESSION['locale'])){
    setlocale($_SESSION['locale']);
}
else{
    //ask for the locale or whatever you need to do
}