[solved] setlocale does not work for php as a suEXEC daemon

Discussion in 'General' started by bobykus, Aug 26, 2014.

  1. bobykus

    bobykus Well-Known Member

    Here is a code - example from php site

    /* Установка голландской локали */
    var_dump(setlocale(LC_ALL, 'nl_NL'));

    /* выводит: vrijdag 22 december 1978 */
    echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 22, 1978));

    /* попытка использовать различные локали для немецкого языка (с PHP 4.3.0) */
    $loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
    echo "На этой системе немецкая локаль имеет имя '$loc_de'";



    bool(false) Friday 22 December 1978На этой системе немецкая локаль имеет имя ''

    Command line php

    /usr/local/lsws/lsphp53/bin/lsphp -c /usr/local/lsws/lsphp53/etc/php.ini ./phptest1.php
    string(5) "nl_NL"
    vrijdag 22 december 1978На этой системе немецкая локаль имеет имя 'de_DE@euro'

    ANy clue why?
  2. NiteWave

    NiteWave Administrator

    the issue is because
    setlocale(LC_ALL, 'nl_NL')=false

    I did simple tests on local box, it's working well as on command line

    >setlocale does not work for php as a suEXEC daemon
    1. does it work on non-daemon mode ?
    2. does it work under apache ?
  3. bobykus

    bobykus Well-Known Member

    Yes, the issue is because setlocale returns false.
    Have no idea if it works in other modes - we have no litespeed QA teem here, sorry.
  4. bobykus

    bobykus Well-Known Member

    And yes, this is related to php 5.3.xx only. 5.4.xx is fine fine.
  5. mistwang

    mistwang LiteSpeed Staff

    Are you using cageFS? try disable CageFS for this user temporarily see if it works.
    Maybe the Locale files are missing under that cage, causes PHP failed to set the locale.
    Otherwise, please add "sleep(30)" at the beginning of the script, then you can locate the process serving the script and strace it to find out what happened.
  6. bobykus

    bobykus Well-Known Member

    No, just plain CentOS6. I'll add sleep and check it of course.
  7. bobykus

    bobykus Well-Known Member

    Ah, OK,

    open("/usr/lib/locale/locale-archive", O_RDONLY) = 9
    fstat(9, {st_mode=S_IFREG|0644, st_size=99158576, ...}) = 0
    mmap(NULL, 99158576, PROT_READ, MAP_PRIVATE, 9, 0) = -1 ENOMEM (Cannot allocate memory)

    Sorry - my bad. Limit for external app was too tight.
  8. bobykus

    bobykus Well-Known Member

    BTW thank you for a tip :)
  9. NiteWave

    NiteWave Administrator

    beautiful result from strace. Thanks!

Share This Page