PHP 8.5.0 Alpha 4 available for testing

Voting

: min(zero, seven)?
(Example: nine)

The Note You're Voting On

ck at claudiokuenzler dot com
4 years ago
If you come across a situation where the translation works fine on CLI but not on Apache, it may be caused by the Perl Apache module.

Basic translate.php:

<?php
// Set locale
putenv("LC_ALL=de_CH.UTF-8");
putenv("LANGUAGE=");
putenv("LANG=de_CH.UTF-8");
$res = setlocale(LC_ALL, 'de_CH.UTF-8', 'de_CH', 'de');
echo
bindtextdomain("homepage", "./locale");
textdomain("homepage");

$results = gettext("My English Text");
if (
$results === "My English Text") {
echo
"Original English was returned. Something wrong\n";
} else {
echo
$results;
}
?>

On the CLI the translation works:

$ php7.3 translate.php
Mein deutscher Text.

But not via Apache web server:

$ curl localhost/translate.php
Original English was returned. Something wrong

Disable Perl module and restart Apache:

# a2dismod perl
# systemctl restart apache2

And suddenly the translation works:

$ curl localhost/translate.php
Mein deutscher Text.

The exact reason for this behaviour is (as of right now) unknown to me.

<< Back to user notes page

To Top