Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iconv implementation missing #25

Closed
alsar opened this issue Apr 9, 2018 · 16 comments
Closed

Iconv implementation missing #25

alsar opened this issue Apr 9, 2018 · 16 comments

Comments

@alsar
Copy link
Contributor

alsar commented Apr 9, 2018

The iconv extension is enabled, but there is no implementation available (like glibc). I tried with 7.2, 7.1 and 5.6 images.

The php.ini output:

iconv support => enabled
iconv implementation => unknown
iconv library version => unknown
iconv.input_encoding => no value => no value
iconv.internal_encoding => no value => no value
iconv.output_encoding => no value => no value

As a result the iconv() function fails with translit:
iconv('utf-8', 'ascii//TRANSLIT', 'test');

Notice: iconv(): Wrong charset, conversion from 'utf-8' to 'ascii//TRANSLIT' is not allowed

csandanov added a commit that referenced this issue Apr 9, 2018
@csandanov
Copy link
Member

Thanks for reporting this, the lib was really missing. The implementation and the version will still be missing despite the fix but you can validate that it's working now by running the following snippet in the container as suggested in docker-library/php#240 (comment)

php -d error_reporting=22527 -d display_errors=1 -r 'var_dump(iconv("UTF-8", "UTF-8//IGNORE", "This is the Euro symbol '\'''\''."));'

If it runs without notices it's all good.

@alsar
Copy link
Contributor Author

alsar commented Apr 10, 2018

It works now. Thank you for the quick fix.

@alsar alsar closed this as completed Apr 10, 2018
@alsar
Copy link
Contributor Author

alsar commented Apr 10, 2018

@csandanov The fix works with the CLI but not with FPM.

CLI environment variables from phpinfo():

LD_PRELOAD => /usr/lib/preloadable_libiconv.so php
$_SERVER['LD_PRELOAD'] => /usr/lib/preloadable_libiconv.so php
$_ENV['LD_PRELOAD'] => /usr/lib/preloadable_libiconv.so php

But those variables are missing when I output phpinfo() with FPM.

@csandanov
Copy link
Member

Yes, that's because FPM has clear_env = yes by default. Added LD_PRELOAD to the list of env vars that always pass through.

@alsar
Copy link
Contributor Author

alsar commented Apr 10, 2018

I tried the updated image. The environment variables are now present, but the iconv function with translit still fails with FPM.

@csandanov
Copy link
Member

Does it work if you set clear_env = yes and LD_PRELOAD=/usr/lib/preloadable_libiconv.so php-fpm?

@alsar
Copy link
Contributor Author

alsar commented Apr 10, 2018

No. The change is visible in php.ini, but it still works only for CLI but not FPM.

@csandanov
Copy link
Member

Right, we run fpm via sudo. Added LD_PRELOAD directly to the command, my example from above now runs without notices via fpm as well.

@alsar
Copy link
Contributor Author

alsar commented Apr 12, 2018

It works now. Thanks.

Just a remark. On my local setup the command php -r "var_dump(iconv('UTF-8', 'ASCII//TRANSLIT', 'tést'));" outputs test, but with your image it's t'est.
Do you know maybe what is this related to? Locales maybe?

@csandanov
Copy link
Member

What's your OS? AFAIK, Linux and Windows use different libs for iconv

@alsar
Copy link
Contributor Author

alsar commented Apr 13, 2018

I'm on Linux.
Ubuntu 16.04 with PHP 7.2.4 with glibc 2.23

@csandanov
Copy link
Member

Could be docker-library/php#240 (comment)

@alsar
Copy link
Contributor Author

alsar commented Apr 13, 2018

Probably.

When I output setlocale(LC_ALL, 0); I get:
on my local installation: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C

inside the container: C.UTF-8;C;C;C;C;C

@csandanov
Copy link
Member

I doubt this issue can be resolved, most likely this caused due to usage of GNU iconv library and not having a good locale support in musl, try using http://php.net/manual/en/transliterator.transliterate.php instead for transliteration:

php -r 'var_dump(transliterator_transliterate("Any-Latin; Latin-ASCII; [\u0080-\u7fff] remove", "A æ Übérmensch på høyeste nivå! И я люблю PHP! есть. fi ¦"));'

@gsusI
Copy link

gsusI commented Sep 11, 2021

Fixed by installing php7-mbstring php7-iconv in that order

RUN apk --no-cache add php7-mbstring php7-iconv

Original solution here: docker-library/php#240 (comment)

@csandanov
Copy link
Member

Fixed in the upstream docker-library/php#1264

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants