Skip to content

Commit a417436

Browse files
committed
Fix behavior on platforms which already measure wall-clock time
1 parent de519e5 commit a417436

File tree

10 files changed

+107
-21
lines changed

10 files changed

+107
-21
lines changed

Zend/zend_ini.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ ZEND_API void zend_ini_refresh_caches(int stage) /* {{{ */
277277

278278
ZEND_API zend_result zend_alter_ini_entry(zend_string *name, zend_string *new_value, int modify_type, int stage) /* {{{ */
279279
{
280-
281-
return zend_alter_ini_entry_ex(name, new_value, modify_type, stage, 0);
280+
return zend_alter_ini_entry_ex(name, new_value, modify_type, stage, 0, 0);
282281
}
283282
/* }}} */
284283

@@ -288,7 +287,7 @@ ZEND_API zend_result zend_alter_ini_entry_chars(zend_string *name, const char *v
288287
zend_string *new_value;
289288

290289
new_value = zend_string_init(value, value_length, !(stage & ZEND_INI_STAGE_IN_REQUEST));
291-
ret = zend_alter_ini_entry_ex(name, new_value, modify_type, stage, 0);
290+
ret = zend_alter_ini_entry_ex(name, new_value, modify_type, stage, 0, 0);
292291
zend_string_release(new_value);
293292
return ret;
294293
}
@@ -300,13 +299,13 @@ ZEND_API zend_result zend_alter_ini_entry_chars_ex(zend_string *name, const char
300299
zend_string *new_value;
301300

302301
new_value = zend_string_init(value, value_length, !(stage & ZEND_INI_STAGE_IN_REQUEST));
303-
ret = zend_alter_ini_entry_ex(name, new_value, modify_type, stage, force_change);
302+
ret = zend_alter_ini_entry_ex(name, new_value, modify_type, stage, force_change, 0);
304303
zend_string_release(new_value);
305304
return ret;
306305
}
307306
/* }}} */
308307

309-
ZEND_API zend_result zend_alter_ini_entry_ex(zend_string *name, zend_string *new_value, int modify_type, int stage, bool force_change) /* {{{ */
308+
ZEND_API zend_result zend_alter_ini_entry_ex(zend_string *name, zend_string *new_value, int modify_type, int stage, bool force_change, bool skip_on_update) /* {{{ */
310309
{
311310
zend_ini_entry *ini_entry;
312311
zend_string *duplicate;
@@ -344,7 +343,7 @@ ZEND_API zend_result zend_alter_ini_entry_ex(zend_string *name, zend_string *new
344343
duplicate = zend_string_copy(new_value);
345344

346345
if (!ini_entry->on_modify
347-
|| ini_entry->on_modify(ini_entry, duplicate, ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3, stage) == SUCCESS) {
346+
|| skip_on_update || ini_entry->on_modify(ini_entry, duplicate, ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3, stage) == SUCCESS) {
348347
if (modified && ini_entry->orig_value != ini_entry->value) { /* we already changed the value, free the changed value */
349348
zend_string_release(ini_entry->value);
350349
}

Zend/zend_ini.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ ZEND_API zend_result zend_register_ini_entries(const zend_ini_entry_def *ini_ent
7575
ZEND_API void zend_unregister_ini_entries(int module_number);
7676
ZEND_API void zend_ini_refresh_caches(int stage);
7777
ZEND_API zend_result zend_alter_ini_entry(zend_string *name, zend_string *new_value, int modify_type, int stage);
78-
ZEND_API zend_result zend_alter_ini_entry_ex(zend_string *name, zend_string *new_value, int modify_type, int stage, bool force_change);
78+
ZEND_API zend_result zend_alter_ini_entry_ex(zend_string *name, zend_string *new_value, int modify_type, int stage, bool force_change, bool skip_on_update);
7979
ZEND_API zend_result zend_alter_ini_entry_chars(zend_string *name, const char *value, size_t value_length, int modify_type, int stage);
8080
ZEND_API zend_result zend_alter_ini_entry_chars_ex(zend_string *name, const char *value, size_t value_length, int modify_type, int stage, int force_change);
8181
ZEND_API zend_result zend_restore_ini_entry(zend_string *name, int stage);

ext/session/session.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2452,7 +2452,7 @@ static int php_session_start_set_ini(zend_string *varname, zend_string *new_valu
24522452
smart_str_appendc(&buf, '.');
24532453
smart_str_append(&buf, varname);
24542454
smart_str_0(&buf);
2455-
ret = zend_alter_ini_entry_ex(buf.s, new_value, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0);
2455+
ret = zend_alter_ini_entry_ex(buf.s, new_value, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0, 0);
24562456
smart_str_free(&buf);
24572457
return ret;
24582458
}

ext/standard/assert.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ PHP_FUNCTION(assert_options)
228228
}
229229

230230
key = zend_string_init("assert.active", sizeof("assert.active")-1, 0);
231-
zend_alter_ini_entry_ex(key, value_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0);
231+
zend_alter_ini_entry_ex(key, value_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0, 0);
232232
zend_string_release_ex(key, 0);
233233
zend_string_release_ex(value_str, 0);
234234
}
@@ -244,7 +244,7 @@ PHP_FUNCTION(assert_options)
244244
}
245245

246246
key = zend_string_init("assert.bail", sizeof("assert.bail")-1, 0);
247-
zend_alter_ini_entry_ex(key, value_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0);
247+
zend_alter_ini_entry_ex(key, value_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0, 0);
248248
zend_string_release_ex(key, 0);
249249
zend_string_release_ex(value_str, 0);
250250
}
@@ -260,7 +260,7 @@ PHP_FUNCTION(assert_options)
260260
}
261261

262262
key = zend_string_init("assert.warning", sizeof("assert.warning")-1, 0);
263-
zend_alter_ini_entry_ex(key, value_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0);
263+
zend_alter_ini_entry_ex(key, value_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0, 0);
264264
zend_string_release_ex(key, 0);
265265
zend_string_release_ex(value_str, 0);
266266
}
@@ -295,7 +295,7 @@ PHP_FUNCTION(assert_options)
295295
}
296296

297297
key = zend_string_init("assert.exception", sizeof("assert.exception")-1, 0);
298-
zend_alter_ini_entry_ex(key, val, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0);
298+
zend_alter_ini_entry_ex(key, val, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0, 0);
299299
zend_string_release_ex(val, 0);
300300
zend_string_release_ex(key, 0);
301301
}

ext/standard/basic_functions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,7 +2128,7 @@ PHP_FUNCTION(ini_set)
21282128
}
21292129
#undef _CHECK_PATH
21302130

2131-
if (zend_alter_ini_entry_ex(varname, new_value_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0) == FAILURE) {
2131+
if (zend_alter_ini_entry_ex(varname, new_value_str, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0, 0) == FAILURE) {
21322132
zval_ptr_dtor_str(return_value);
21332133
RETVAL_FALSE;
21342134
}
@@ -2171,7 +2171,7 @@ PHP_FUNCTION(set_include_path)
21712171
}
21722172

21732173
key = zend_string_init("include_path", sizeof("include_path") - 1, 0);
2174-
if (zend_alter_ini_entry_ex(key, new_value, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0) == FAILURE) {
2174+
if (zend_alter_ini_entry_ex(key, new_value, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0, 0) == FAILURE) {
21752175
zend_string_release_ex(key, 0);
21762176
zval_ptr_dtor_str(return_value);
21772177
RETURN_FALSE;

main/main.c

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,32 +385,55 @@ static void php_binary_init(void)
385385
}
386386
/* }}} */
387387

388-
/* {{{ PHP_INI_MH */
389-
static PHP_INI_MH(OnUpdateTimeout)
388+
static void updateTimeout(zend_string *new_value, int stage)
390389
{
391-
if (stage==PHP_INI_STAGE_STARTUP) {
390+
if (stage == PHP_INI_STAGE_STARTUP) {
392391
/* Don't set a timeout on startup, only per-request */
393392
ZEND_ATOL(EG(timeout_seconds), ZSTR_VAL(new_value));
394-
return SUCCESS;
393+
return;
395394
}
396395
zend_unset_timeout();
397396
ZEND_ATOL(EG(timeout_seconds), ZSTR_VAL(new_value));
398397
zend_set_timeout(EG(timeout_seconds), 0);
398+
}
399+
400+
/* {{{ PHP_INI_MH */
401+
static PHP_INI_MH(OnUpdateTimeout)
402+
{
403+
updateTimeout(new_value, stage);
404+
405+
#if defined(WIN32) || defined(__CYGWIN__) || defined(__PASE__)
406+
if (stage != PHP_INI_STAGE_STARTUP) {
407+
zend_string *alias_name = zend_string_init("max_execution_wall_time", sizeof("max_execution_wall_time") - 1, !(stage & ZEND_INI_STAGE_IN_REQUEST));
408+
zend_alter_ini_entry_ex(alias_name, new_value, PHP_INI_ALL, stage, 0, 1);
409+
zend_string_release(alias_name);
410+
}
411+
#endif
412+
399413
return SUCCESS;
400414
}
401415
/* }}} */
402416

403417
/* {{{ PHP_INI_MH */
404418
static PHP_INI_MH(OnUpdateWallTimeout)
405419
{
406-
if (stage==PHP_INI_STAGE_STARTUP) {
420+
#if defined(WIN32) || defined(__CYGWIN__) || defined(__PASE__)
421+
updateTimeout(new_value, stage);
422+
if (stage != PHP_INI_STAGE_STARTUP) {
423+
zend_string *alias_name = zend_string_init("max_execution_time", sizeof("max_execution_time") - 1, !(stage & ZEND_INI_STAGE_IN_REQUEST));
424+
zend_alter_ini_entry_ex(alias_name, new_value, PHP_INI_ALL, stage, 0, 1);
425+
zend_string_release(alias_name);
426+
}
427+
#else
428+
if (stage == PHP_INI_STAGE_STARTUP) {
407429
/* Don't set a timeout on startup, only per-request */
408430
ZEND_ATOL(EG(wall_timeout_seconds), ZSTR_VAL(new_value));
409431
return SUCCESS;
410432
}
411433
zend_unset_wall_timeout();
412434
ZEND_ATOL(EG(wall_timeout_seconds), ZSTR_VAL(new_value));
413435
zend_set_wall_timeout(EG(wall_timeout_seconds), 0);
436+
#endif
414437
return SUCCESS;
415438
}
416439
/* }}} */
@@ -1702,7 +1725,9 @@ int php_request_startup(void)
17021725
} else {
17031726
zend_set_timeout(PG(max_input_time), 1);
17041727
}
1728+
#if !defined(WIN32) && !defined(__CYGWIN__) && !defined(__PASE__)
17051729
zend_set_wall_timeout(EG(wall_timeout_seconds), 1);
1730+
#endif
17061731

17071732
/* Disable realpath cache if an open_basedir is set */
17081733
if (PG(open_basedir) && *PG(open_basedir)) {
@@ -1792,7 +1817,9 @@ void php_request_shutdown(void *dummy)
17921817
/* 4. Reset max_execution_time and max_execution_wall_time (no longer executing php code after response sent) */
17931818
zend_try {
17941819
zend_unset_timeout();
1820+
#if !defined(WIN32) && !defined(__CYGWIN__) && !defined(__PASE__)
17951821
zend_unset_wall_timeout();
1822+
#endif
17961823
} zend_end_try();
17971824

17981825
/* 5. Call all extensions RSHUTDOWN functions */

main/php_ini.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int
796796

797797
/* Walk through config hash and alter matching ini entries using the values found in the hash */
798798
ZEND_HASH_FOREACH_STR_KEY_VAL(source_hash, str, data) {
799-
zend_alter_ini_entry_ex(str, Z_STR_P(data), modify_type, stage, 0);
799+
zend_alter_ini_entry_ex(str, Z_STR_P(data), modify_type, stage, 0, 0);
800800
} ZEND_HASH_FOREACH_END();
801801
}
802802
/* }}} */

sapi/phpdbg/phpdbg_wait.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void phpdbg_webdata_decompress(char *msg, int len) {
318318

319319
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zvp), key, ini_entry) {
320320
if (key && Z_TYPE_P(ini_entry) == IS_STRING) {
321-
zend_alter_ini_entry_ex(key, Z_STR_P(ini_entry), ZEND_INI_PERDIR, ZEND_INI_STAGE_HTACCESS, 1);
321+
zend_alter_ini_entry_ex(key, Z_STR_P(ini_entry), ZEND_INI_PERDIR, ZEND_INI_STAGE_HTACCESS, 1, 0);
322322
}
323323
} ZEND_HASH_FOREACH_END();
324324
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Test that max_execution_wall_time is an alias of max_execution_time on Unix-based platforms
3+
--SKIPIF--
4+
<?php
5+
if (PHP_OS_FAMILY === "WIN") {
6+
die('skip not for Windows');
7+
}
8+
?>
9+
--INI--
10+
max_execution_time=0
11+
max_execution_wall_time=0
12+
--FILE--
13+
<?php
14+
15+
ini_set("max_execution_wall_time", 1);
16+
17+
var_dump(ini_get("max_execution_wall_time"));
18+
var_dump(ini_get("max_execution_time"));
19+
20+
ini_set("max_execution_time", 2);
21+
22+
var_dump(ini_get("max_execution_wall_time"));
23+
var_dump(ini_get("max_execution_time"));
24+
25+
?>
26+
--EXPECTF--
27+
string(1) "1"
28+
string(1) "0"
29+
string(1) "1"
30+
string(1) "2"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Test that max_execution_wall_time is an alias of max_execution_time on Windows
3+
--SKIPIF--
4+
<?php
5+
if (PHP_OS_FAMILY !== "WIN") {
6+
die('skip only for Windows');
7+
}
8+
?>
9+
--INI--
10+
max_execution_time=0
11+
max_execution_wall_time=0
12+
--FILE--
13+
<?php
14+
15+
ini_set("max_execution_wall_time", 1);
16+
17+
var_dump(ini_get("max_execution_wall_time"));
18+
var_dump(ini_get("max_execution_time"));
19+
20+
ini_set("max_execution_time", 2);
21+
22+
var_dump(ini_get("max_execution_wall_time"));
23+
var_dump(ini_get("max_execution_time"));
24+
25+
?>
26+
--EXPECTF--
27+
string(1) "1"
28+
string(1) "1"
29+
string(1) "2"
30+
string(1) "2"

0 commit comments

Comments
 (0)