[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bossm8 opened this issue Mar 1, 2024 · 1 comment

Comments

@bossm8
Copy link
bossm8 commented Mar 1, 2024

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)

@bukka
Copy link
Member
bukka commented Mar 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants