Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Gettext problems (like non-thread-safe?)

I want to start using gettext to handle my translations on web projects (PHP 5). Since it is a widely used standard with a good reputation it seems to be the best choice.

However, I'm also hearing things about server incompatibly and it being non-thread-safe. What does this mean for my projects that use it then? Since I build things that many people use, it's very important that my code works.

Are we talking about minor problems (like people still using PHP 4) or major problems like distribution and installation of gettext on websevers being low?

like image 274
Xeoncross Avatar asked Oct 29 '09 20:10

Xeoncross


2 Answers

Threads problem only apply if one uses embedded PHP (Apache's mod-php for example) and runs server that uses threads (like Apache server with worker-mpm).

So - thread safety issue does not apply to you if:

  1. you use NGINX server(it doesn't use threads.)
  2. You use Apache (with either threaded MPM or not) and PHP in fastcgi mode
  3. You use Apache with non-threaded MPM (as prefork-MPM) and PHP in mod-php mode.

So - most people with default Apache install shouldn't worry about gettext not being thread safe, as default apache's install in most distro's uses non-threaded prefork-MPM!

P.S. also - keep in mind that Apache on Windows is threaded.

like image 118
ThatGuy Avatar answered Nov 19 '22 23:11

ThatGuy


I think play some more with the php manual comments portion should revile more information....one of the comments from the manual on gettext section

The GNU gettext library works on a per-process, not per-thread basis. This means that in a multi-user setting such as the Apache web server it will only work with a prefork MPM (i.e. one process per user). Worker and other threaded MPMs will not work.

In addition, many users control GNU gettext by setting system environment variables such as LANG. This is not a good solution for a web server environment due to an obvious race condition.

http://www.php.net/manual/en/gettext.setup.php

like image 21
Ronald Conco Avatar answered Nov 19 '22 22:11

Ronald Conco