Skip to content

Commit ca22aad

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

File tree

10 files changed

+98
-22
lines changed

10 files changed

+98
-22
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: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,32 +385,51 @@ 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+
zend_string *alias_name = zend_string_init("max_execution_wall_time", sizeof("max_execution_wall_time") - 1, !(stage & ZEND_INI_STAGE_IN_REQUEST));
407+
zend_alter_ini_entry_ex(alias_name, new_value, PHP_INI_ALL, stage, 0, 1);
408+
zend_string_release(alias_name);
409+
#endif
410+
399411
return SUCCESS;
400412
}
401413
/* }}} */
402414

403415
/* {{{ PHP_INI_MH */
404416
static PHP_INI_MH(OnUpdateWallTimeout)
405417
{
406-
if (stage==PHP_INI_STAGE_STARTUP) {
418+
#if defined(WIN32) || defined(__CYGWIN__) || defined(__PASE__)
419+
updateTimeout(new_value, stage);
420+
zend_string *alias_name = zend_string_init("max_execution_time", sizeof("max_execution_time") - 1, !(stage & ZEND_INI_STAGE_IN_REQUEST));
421+
zend_alter_ini_entry_ex(alias_name, new_value, PHP_INI_ALL, stage, 0, 1);
422+
zend_string_release(alias_name);
423+
#else
424+
if (stage == PHP_INI_STAGE_STARTUP) {
407425
/* Don't set a timeout on startup, only per-request */
408426
ZEND_ATOL(EG(wall_timeout_seconds), ZSTR_VAL(new_value));
409427
return SUCCESS;
410428
}
411429
zend_unset_wall_timeout();
412430
ZEND_ATOL(EG(wall_timeout_seconds), ZSTR_VAL(new_value));
413431
zend_set_wall_timeout(EG(wall_timeout_seconds), 0);
432+
#endif
414433
return SUCCESS;
415434
}
416435
/* }}} */
@@ -702,8 +721,8 @@ PHP_INI_BEGIN()
702721
STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals)
703722
STD_PHP_INI_ENTRY("sys_temp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, sys_temp_dir, php_core_globals, core_globals)
704723
STD_PHP_INI_ENTRY("include_path", PHP_INCLUDE_PATH, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals)
705-
PHP_INI_ENTRY("max_execution_time", "30", PHP_INI_ALL, OnUpdateTimeout)
706724
PHP_INI_ENTRY("max_execution_wall_time", "0", PHP_INI_ALL, OnUpdateWallTimeout)
725+
PHP_INI_ENTRY("max_execution_time", "30", PHP_INI_ALL, OnUpdateTimeout)
707726
STD_PHP_INI_ENTRY("open_basedir", NULL, PHP_INI_ALL, OnUpdateBaseDir, open_basedir, php_core_globals, core_globals)
708727

709728
STD_PHP_INI_BOOLEAN("file_uploads", "1", PHP_INI_SYSTEM, OnUpdateBool, file_uploads, php_core_globals, core_globals)
@@ -1702,7 +1721,9 @@ int php_request_startup(void)
17021721
} else {
17031722
zend_set_timeout(PG(max_input_time), 1);
17041723
}
1724+
#if !defined(WIN32) && !defined(__CYGWIN__) && !defined(__PASE__)
17051725
zend_set_wall_timeout(EG(wall_timeout_seconds), 1);
1726+
#endif
17061727

17071728
/* Disable realpath cache if an open_basedir is set */
17081729
if (PG(open_basedir) && *PG(open_basedir)) {
@@ -1792,7 +1813,9 @@ void php_request_shutdown(void *dummy)
17921813
/* 4. Reset max_execution_time and max_execution_wall_time (no longer executing php code after response sent) */
17931814
zend_try {
17941815
zend_unset_timeout();
1816+
#if !defined(WIN32) && !defined(__CYGWIN__) && !defined(__PASE__)
17951817
zend_unset_wall_timeout();
1818+
#endif
17961819
} zend_end_try();
17971820

17981821
/* 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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
--FILE--
10+
<?php
11+
12+
ini_set("max_execution_wall_time", 1);
13+
14+
var_dump(ini_get("max_execution_wall_time"));
15+
var_dump(ini_get("max_execution_time"));
16+
17+
ini_set("max_execution_time", 2);
18+
19+
var_dump(ini_get("max_execution_wall_time"));
20+
var_dump(ini_get("max_execution_time"));
21+
22+
?>
23+
--EXPECTF--
24+
string(1) "1"
25+
string(1) "0"
26+
string(1) "1"
27+
string(1) "2"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
--FILE--
10+
<?php
11+
12+
ini_set("max_execution_wall_time", 1);
13+
14+
var_dump(ini_get("max_execution_wall_time"));
15+
var_dump(ini_get("max_execution_time"));
16+
17+
ini_set("max_execution_time", 2);
18+
19+
var_dump(ini_get("max_execution_wall_time"));
20+
var_dump(ini_get("max_execution_time"));
21+
22+
?>
23+
--EXPECTF--
24+
string(1) "1"
25+
string(1) "1"
26+
string(1) "2"
27+
string(1) "2"

0 commit comments

Comments
 (0)