Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8082337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:03:44+00:00 2026-06-05T17:03:44+00:00

I’ve been reading about locales in PHP and it seems setlocale() has problems with

  • 0

I’ve been reading about locales in PHP and it seems setlocale() has problems with threads. (I’m not too familiar with threads – the docs mention it is not thread safe)

I’d like to give my project the ability to deal with certain number formats and the Intl extension seems interesting.

http://php.net/manual/en/book.intl.php

Should I expect the same problems that setlocale() has using the Intl extension?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:03:46+00:00Added an answer on June 5, 2026 at 5:03 pm

    Ok, I was curious about this myself as well, so I devised a test.

    First I tested setlocale() with these two files:

    <?php
    # locale1.php
    error_reporting( E_ALL | E_STRICT );
    
    date_default_timezone_set( 'Europe/Amsterdam' );
    setlocale( LC_ALL, 'dutch_nld' ); // awkward Windows locale string
    
    sleep( 10 ); // let's sleep for a bit here
    
    echo strftime( '%A, %B %d, %Y %X %Z', time() );
    

    and

    <?php
    # locale2.php
    error_reporting( E_ALL | E_STRICT );
    
    date_default_timezone_set( 'America/Los_Angeles' );
    setlocale( LC_ALL, 'english_usa' ); // awkward Windows locale string
    
    echo strftime( '%A, %B %d, %Y %X %Z', time() );
    

    Then I executed them in two seperate tabs. First locale1.php, that sleeps for 10 seconds after setting the locale, giving us time to execute locale2.php in the meanwhile.

    To my surprise locale2.php isn’t even allowed to change the locale correctly. It appears sleep( 10 ) in locale1.php hijacks the Apache/PHP process in such a way that it doesn’t allow locale2.php to alter the locale in the meanwhile. It does however echo the date in the meanwhile of course, just not localized as you’d expect.

    Edit: sorry, scrap that. It appears locale2.php does change the locale and locale1.php then prints the English date in stead of Dutch after sleeping. So that does appear to be in accordance with what is expected behavior from setlocale().
    /Edit

    Then, I tested IntlDateFormatter with these two files:

    <?php
    # locale1.php
    error_reporting( E_ALL | E_STRICT );
    
    $dateFormatter = new IntlDateFormatter(
        'nl_NL',
         IntlDateFormatter::FULL,
         IntlDateFormatter::FULL,
         'Europe/Amsterdam'
    );
    
    sleep( 10 ); // let's sleep for a bit here
    
    echo $dateFormatter->format( time() );
    

    and

    <?php
    # locale2.php
    error_reporting( E_ALL | E_STRICT );
    
    $dateFormatter = new IntlDateFormatter(
        'en_US',
         IntlDateFormatter::FULL,
         IntlDateFormatter::FULL,
         'America/Los_Angeles'
    );
    
    echo $dateFormatter->format( time() );
    

    and then executed them again in two separate tabs, the same way as with the first set of files. This does give the expected results: while locale1.php is sleeping locale2.php nicely prints a date in American-English according to American rules, after which locale1.php nicely prints a date in Dutch according to Dutch rules.

    So, concluding, it appears Intl is safe from that setlocale problem.

    But also mind Hyunmin Kim’s answer of course. I couldn’t comment on that, due to lack of experience with using Intl. I only recently discovered Intl.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
Basically, what I'm trying to create is a page of div tags, each has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.