Skip to content

Setting boolean values via env in php config fails for all values other than 1 and "" #13563

Closed

Description

@bossm8

Description

Configuring php in a docker container which is configurable via env I noticed strange behaviour when using ${ENV} in php-fpm config files for boolean values. The only values accepted are 1 and "" when I would expect no, yes, true, false etc. to be accepted. (I could not find a documentation somewhere which describes accepted values)

The following code:

export PHP_FPM_CLEAR_ENV=true

/etc/php-fpm.d/www.conf:

[www]

listen = /run/php-fpm/www.sock

clear_env = ${PHP_FPM_CLEAR_ENV}

(...)
php-fpm -tt

Resulted in this output:

[01-Mar-2024 11:14:47] ERROR: [/etc/php-fpm.d/www.conf:5] unable to parse value for entry 'clear_env': invalid boolean value
[01-Mar-2024 11:14:47] ERROR: Unable to include /etc/php-fpm.d/www.conf from /etc/php-fpm.conf at line 5
[01-Mar-2024 11:14:47] ERROR: failed to load configuration file '/etc/php-fpm.conf'
[01-Mar-2024 11:14:47] ERROR: FPM initialization failed

But I expected this output instead:

(...)
[01-Mar-2024 11:21:19] NOTICE: [www]
[01-Mar-2024 11:21:19] NOTICE:  clear_env = yes
(...)

The same applies for all boolean values, and I could eventually find the code which produces the above error in my attempt to get the container running with env variables:

static char *fpm_conf_set_boolean(zval *value, void **config, intptr_t offset) /* {{{ */
{
	zend_string *val = Z_STR_P(value);
	bool value_y = zend_string_equals_literal(val, "1");
	bool value_n = ZSTR_LEN(val) == 0; /* Empty string is the only valid false value */

	if (!value_y && !value_n) {
		return "invalid boolean value";
	}

	* (int *) ((char *) *config + offset) = value_y ? 1 : 0;
	return NULL;
}

From https://github.com/php/php-src/blob/a48ed12ea9d3d59d307c77131092cff13acee2d0/sapi/fpm/fpm/fpm_conf.c#L213C1-L225C2

php-fpm --version
PHP 8.1.27 (fpm-fcgi) (built: Dec 19 2023 20:35:55)
Copyright (c) The PHP Group
Zend Engine v4.1.27, Copyright (c) Zend Technologies

PHP Version

8.1.27

Operating System

Rocky Linux 9 (Docker rockylinux:9 sha256:c944604c0c759f5d164ffbdf0bbab2fac582b739938937403c067ab634a0518a)

Activity

  1. bukka commented on Mar 8, 2024

    @bukka
    Member

    I just had a look and it is because FPM relies on conversion in zend_ini_scanner which converts the boolean values either to "1" or "". This is however not the case if value is supplied through the env variable which is copied as supplied. I need to think if this makes more sense to handle in INI or in FPM. I guess we can classify this as a bug even though it is somewhere between. But changing (fixing) it should not do any harm as it is currently not working.

  2. added 2 commits that reference this issue on Mar 22, 2024
    c31f8ea
    d0a8d41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions