Skip to content

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

Closed
@bossm8

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)

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