Skip to content

Commit e3798c2

Browse files
TimWollamvorisek
andauthored
sapi/cli: Extend --ini to print INI settings changed from the builtin default (#17459)
* sapi/cli: Extend `--ini` to print INI settings changed from the builtin default This is intended to make it easier to check whether or not a given INI setting is changed from the default when building reproducers for a bugreport, without forgetting any that might be relevant to the report. As an example, running `sapi/cli/php -c /etc/php/8.3/cli/ --ini` on my Ubuntu will now output: Configuration File (php.ini) Path: /usr/local/lib Loaded Configuration File: /etc/php/8.3/cli/php.ini Scan for additional .ini files in: (none) Additional .ini files parsed: (none) Non-standard INI settings: allow_url_include: "0" -> "" auto_append_file: (none) -> "" auto_prepend_file: (none) -> "" display_errors: "1" -> "" display_startup_errors: "1" -> "" enable_dl: "1" -> "" error_reporting: (none) -> "22527" html_errors: "1" -> "0" ignore_repeated_errors: "0" -> "" ignore_repeated_source: "0" -> "" implicit_flush: "0" -> "1" log_errors: "0" -> "1" mail.add_x_header: "0" -> "" mail.mixed_lf_and_crlf: "0" -> "" max_execution_time: "30" -> "0" memory_limit: "128M" -> "-1" request_order: (none) -> "GP" session.cookie_httponly: "0" -> "" session.gc_divisor: "100" -> "1000" session.gc_probability: "1" -> "0" session.sid_bits_per_character: "4" -> "5" session.sid_length: "32" -> "26" short_open_tag: "1" -> "" unserialize_callback_func: (none) -> "" user_dir: (none) -> "" variables_order: "EGPCS" -> "GPCS" zend.assertions: "1" -> "-1" zend.exception_ignore_args: "0" -> "1" zend.exception_string_param_max_len: "15" -> "0" * Improve phrasing Co-authored-by: Michael Voříšek <mvorisek@mvorisek.cz> * NEWS/UPGRADING --------- Co-authored-by: Michael Voříšek <mvorisek@mvorisek.cz>
1 parent 107bd08 commit e3798c2

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.5.0alpha1
44

5+
- CLI:
6+
. Extended --ini to print INI settings changed from the builtin default.
7+
(timwolla)
8+
59
- COM:
610
. Fixed property access of PHP objects wrapped in variant. (cmb)
711
. Fixed method calls for PHP objects wrapped in variant. (cmb)

UPGRADING

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ PHP 8.5 UPGRADE NOTES
107107
- CLI:
108108
. Trying to set a process title that is too long with cli_set_process_title()
109109
will now fail instead of silently truncating the given title.
110+
. --ini will now print INI settings changed from the builtin default.
110111

111112
========================================
112113
4. Deprecated Functionality

Zend/zend_ini.c

+1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ ZEND_API zend_result zend_register_ini_entries_ex(const zend_ini_entry_def *ini_
225225

226226
while (ini_entry->name) {
227227
p = pemalloc(sizeof(zend_ini_entry), 1);
228+
p->def = ini_entry;
228229
p->name = zend_string_init_interned(ini_entry->name, ini_entry->name_length, 1);
229230
p->on_modify = ini_entry->on_modify;
230231
p->mh_arg1 = ini_entry->mh_arg1;

Zend/zend_ini.h

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct _zend_ini_entry {
6060
uint8_t orig_modifiable;
6161
uint8_t modified;
6262

63+
const zend_ini_entry_def *def;
6364
};
6465

6566
BEGIN_EXTERN_C()

sapi/cli/php_cli.c

+33
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,14 @@ BOOL WINAPI php_cli_win32_ctrl_handler(DWORD sig)
588588
#endif
589589
/*}}}*/
590590

591+
static int zend_ini_entry_cmp(Bucket *a, Bucket *b)
592+
{
593+
zend_ini_entry *A = Z_PTR(a->val);
594+
zend_ini_entry *B = Z_PTR(b->val);
595+
596+
return zend_binary_strcasecmp(ZSTR_VAL(A->name), ZSTR_LEN(A->name), ZSTR_VAL(B->name), ZSTR_LEN(B->name));
597+
}
598+
591599
static int do_cli(int argc, char **argv) /* {{{ */
592600
{
593601
int c;
@@ -1096,6 +1104,31 @@ static int do_cli(int argc, char **argv) /* {{{ */
10961104
zend_printf("Loaded Configuration File: %s\n", php_ini_opened_path ? php_ini_opened_path : "(none)");
10971105
zend_printf("Scan for additional .ini files in: %s\n", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
10981106
zend_printf("Additional .ini files parsed: %s\n", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
1107+
zend_printf("\n");
1108+
zend_printf("Non-default INI settings:\n");
1109+
zend_ini_entry *ini_entry;
1110+
HashTable *sorted = zend_array_dup(EG(ini_directives));
1111+
zend_array_sort(sorted, zend_ini_entry_cmp, 1);
1112+
ZEND_HASH_PACKED_FOREACH_PTR(sorted, ini_entry) {
1113+
if (ini_entry->value == NULL && ini_entry->def->value == NULL) {
1114+
continue;
1115+
}
1116+
if (ini_entry->value != NULL && ini_entry->def->value != NULL && zend_string_equals_cstr(ini_entry->value, ini_entry->def->value, ini_entry->def->value_length)) {
1117+
continue;
1118+
}
1119+
1120+
zend_printf(
1121+
"%s: %s%s%s -> %s%s%s\n",
1122+
ZSTR_VAL(ini_entry->name),
1123+
ini_entry->def->value ? "\"" : "",
1124+
ini_entry->def->value ? ini_entry->def->value : "(none)",
1125+
ini_entry->def->value ? "\"" : "",
1126+
ini_entry->value ? "\"" : "",
1127+
ini_entry->value ? ZSTR_VAL(ini_entry->value) : "(none)",
1128+
ini_entry->value ? "\"" : ""
1129+
);
1130+
} ZEND_HASH_FOREACH_END();
1131+
zend_array_destroy(sorted);
10991132
break;
11001133
}
11011134
}

0 commit comments

Comments
 (0)