php/php-src — pull request #598 by pda (2014-02-19 22:22:24+00:00)
Title: php-fpm.conf preserve_environment = yes prevents clearenv() in workers.

Summary
-------

This patch adds a `preserve_environment` boolean option to `php-fpm.conf`, making it possible to pass standard environment variables to web apps running under PHP-FPM.

Usage
-----

Configure php-fpm.conf:

```ini
[www]
preserve_environment = yes
```

Run php-fpm with environment variables:

```sh
export DATABASE_URL="mysql://john:c1t1z3n@127.0.0.1:3306/widgets"
php5-fpm
```

Access environment variables from PHP:

```php
connect(getenv("DATABASE_URL") ?: "mysql://user:pass@localhost/default");
```

Background
----------

Currently, FPM workers always clear their environment when they spawn. This makes it impossible to configure a web application by passing standard environment variables.

*(Environment variables can be whitelisted or statically set in [php-fpm's pool config][1], but it should not be necessary, and is sometimes impossible, to edit configuration files to pass environment to a process).*

[The Twelve Factor App][2], and [Heroku][3], and other modern platforms/practices, advocate passing arbitrary configuration to web applications using standard unix environment variables. [Docker containers][4] are parametized by environment variables.

This patch does not change the default behavior, so is fully backwards compatible.

[1]: http://www.php.net/manual/en/install.fpm.configuration.php#example-60
[2]: http://12factor.net/config
[3]: https://devcenter.heroku.com/articles/config-vars
[4]: http://docs.docker.io/en/latest/reference/run/#env-environment-variables