title: How do you narrow locale/codepage context in modern PHP?
body: <p>I have <code>php_mod</code> 7.2.31 running under LightSpeed, the environment locale is UTF8. <a href="https://codereview.stackexchange.com/questions/245387/php-mysql-beginner-any-tips-appreciated-on-the-approach/245396?noredirect=1#comment481922_245396">My very tiny test project</a> only need to work with ASCII data, however, because env. locale is UTF8, <code>ctype_alnum()</code> check is skewed now. I could resolve it by call to <code>setlocale()</code>, however, according to the docs <code>setlocale()</code> is unsafe in threaded environment:</p>
  <blockquote>
  <p>Warning The locale information is maintained per process, not per
  thread. If you are running PHP on a multithreaded server API like IIS,
  HHVM 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().</p>
  </blockquote>
  <p>I guess this makes sense. Hosting is managed by my provider, so I dont know all the details about it but for safety sake I'm assuming it is multithreaded. How do people handle such cases? My guesses so far:</p>
  <ol>
  <li>Give up and process everything in UTF/multibyte</li>
  <li>Use preg_match() (as with any regex matching in every other language I assume it always slower then native string/character tools)</li>
  <li>Use some clever mechanism to manage locales/charsets?</li>
  </ol>