Skip to content

Commit b2dbf0a

Browse files
committed
Remove opcache.consistency_checks
This feature has been broken at least since the tracing JIT and inheritance cache have been introduced. The attempted fix (GH-10798) was too complex. We have thus decided to remove this feature for now. Closes GH-11832
1 parent 4140394 commit b2dbf0a

8 files changed

+9
-75
lines changed

UPGRADING

+9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ PHP 8.3 UPGRADE NOTES
5050
. C functions that have a return type of void now return null instead of
5151
returning the following object object(FFI\CData:void) { }
5252

53+
- Opcache:
54+
. The opcache.consistency_checks INI directive was removed. This feature was
55+
broken with the tracing JIT, as well as with inheritance cache, and has been
56+
disabled without a way to enable it since PHP 8.1.18 and PHP 8.2.5. Both the
57+
tracing JIT and inheritance cache may modify shm after the script has been
58+
persisted, invalidating its checksum. The attempted fix skipped over the
59+
modifiable pointers but was rejected due to complexity. For this reason, it
60+
was decided to remove the feature instead.
61+
5362
- Standard:
5463
. The range() function has had various changes:
5564
* A TypeError is now thrown when passing objects, resources, or arrays

ext/opcache/ZendAccelerator.c

-20
Original file line numberDiff line numberDiff line change
@@ -1538,8 +1538,6 @@ static zend_persistent_script *store_script_in_file_cache(zend_persistent_script
15381538
(size_t)ZCG(mem));
15391539
}
15401540

1541-
new_persistent_script->dynamic_members.checksum = zend_accel_script_checksum(new_persistent_script);
1542-
15431541
zend_file_cache_script_store(new_persistent_script, /* is_shm */ false);
15441542

15451543
return new_persistent_script;
@@ -1653,8 +1651,6 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr
16531651
(size_t)ZCG(mem));
16541652
}
16551653

1656-
new_persistent_script->dynamic_members.checksum = zend_accel_script_checksum(new_persistent_script);
1657-
16581654
/* store script structure in the hash table */
16591655
bucket = zend_accel_hash_update(&ZCSG(hash), new_persistent_script->script.filename, 0, new_persistent_script);
16601656
if (bucket) {
@@ -2131,20 +2127,6 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
21312127
}
21322128
}
21332129

2134-
/* if turned on - check the compiled script ADLER32 checksum */
2135-
if (persistent_script && ZCG(accel_directives).consistency_checks
2136-
&& persistent_script->dynamic_members.hits % ZCG(accel_directives).consistency_checks == 0) {
2137-
2138-
unsigned int checksum = zend_accel_script_checksum(persistent_script);
2139-
if (checksum != persistent_script->dynamic_members.checksum ) {
2140-
/* The checksum is wrong */
2141-
zend_accel_error(ACCEL_LOG_INFO, "Checksum failed for '%s': expected=0x%08x, found=0x%08x",
2142-
ZSTR_VAL(persistent_script->script.filename), persistent_script->dynamic_members.checksum, checksum);
2143-
zend_accel_lock_discard_script(persistent_script);
2144-
persistent_script = NULL;
2145-
}
2146-
}
2147-
21482130
/* Check the second level cache */
21492131
if (!persistent_script && ZCG(accel_directives).file_cache) {
21502132
persistent_script = zend_file_cache_script_load(file_handle);
@@ -4280,8 +4262,6 @@ static zend_persistent_script* preload_script_in_shared_memory(zend_persistent_s
42804262
(size_t)ZCG(mem));
42814263
}
42824264

4283-
new_persistent_script->dynamic_members.checksum = zend_accel_script_checksum(new_persistent_script);
4284-
42854265
/* store script structure in the hash table */
42864266
bucket = zend_accel_hash_update(&ZCSG(hash), new_persistent_script->script.filename, 0, new_persistent_script);
42874267
if (bucket) {

ext/opcache/ZendAccelerator.h

-5
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,10 @@ typedef struct _zend_persistent_script {
132132
void *mem; /* shared memory area used by script structures */
133133
size_t size; /* size of used shared memory */
134134

135-
/* All entries that shouldn't be counted in the ADLER32
136-
* checksum must be declared in this struct
137-
*/
138135
struct zend_persistent_script_dynamic_members {
139136
time_t last_used;
140137
zend_ulong hits;
141138
unsigned int memory_consumption;
142-
unsigned int checksum;
143139
time_t revalidate;
144140
} dynamic_members;
145141
} zend_persistent_script;
@@ -149,7 +145,6 @@ typedef struct _zend_accel_directives {
149145
zend_long max_accelerated_files;
150146
double max_wasted_percentage;
151147
char *user_blacklist_filename;
152-
zend_long consistency_checks;
153148
zend_long force_restart_timeout;
154149
bool use_cwd;
155150
bool ignore_dups;

ext/opcache/tests/gh8065.phpt

-26
This file was deleted.

ext/opcache/zend_accelerator_module.c

-15
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,6 @@ static ZEND_INI_MH(OnUpdateMaxWastedPercentage)
129129
return SUCCESS;
130130
}
131131

132-
static ZEND_INI_MH(OnUpdateConsistencyChecks)
133-
{
134-
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
135-
zend_long consistency_checks = atoi(ZSTR_VAL(new_value));
136-
137-
if (consistency_checks != 0) {
138-
zend_accel_error(ACCEL_LOG_WARNING, "opcache.consistency_checks is reset back to 0 because it does not work properly (see GH-8065, GH-10624).\n");
139-
return FAILURE;
140-
}
141-
*p = 0;
142-
return SUCCESS;
143-
}
144-
145132
static ZEND_INI_MH(OnEnable)
146133
{
147134
if (stage == ZEND_INI_STAGE_STARTUP ||
@@ -289,7 +276,6 @@ ZEND_INI_BEGIN()
289276
STD_PHP_INI_ENTRY("opcache.interned_strings_buffer", "8" , PHP_INI_SYSTEM, OnUpdateInternedStringsBuffer, accel_directives.interned_strings_buffer, zend_accel_globals, accel_globals)
290277
STD_PHP_INI_ENTRY("opcache.max_accelerated_files" , "10000", PHP_INI_SYSTEM, OnUpdateMaxAcceleratedFiles, accel_directives.max_accelerated_files, zend_accel_globals, accel_globals)
291278
STD_PHP_INI_ENTRY("opcache.max_wasted_percentage" , "5" , PHP_INI_SYSTEM, OnUpdateMaxWastedPercentage, accel_directives.max_wasted_percentage, zend_accel_globals, accel_globals)
292-
STD_PHP_INI_ENTRY("opcache.consistency_checks" , "0" , PHP_INI_ALL , OnUpdateConsistencyChecks, accel_directives.consistency_checks, zend_accel_globals, accel_globals)
293279
STD_PHP_INI_ENTRY("opcache.force_restart_timeout" , "180" , PHP_INI_SYSTEM, OnUpdateLong, accel_directives.force_restart_timeout, zend_accel_globals, accel_globals)
294280
STD_PHP_INI_ENTRY("opcache.revalidate_freq" , "2" , PHP_INI_ALL , OnUpdateLong, accel_directives.revalidate_freq, zend_accel_globals, accel_globals)
295281
STD_PHP_INI_ENTRY("opcache.file_update_protection", "2" , PHP_INI_ALL , OnUpdateLong, accel_directives.file_update_protection, zend_accel_globals, accel_globals)
@@ -804,7 +790,6 @@ ZEND_FUNCTION(opcache_get_configuration)
804790
add_assoc_long(&directives, "opcache.interned_strings_buffer",ZCG(accel_directives).interned_strings_buffer);
805791
add_assoc_long(&directives, "opcache.max_accelerated_files", ZCG(accel_directives).max_accelerated_files);
806792
add_assoc_double(&directives, "opcache.max_wasted_percentage", ZCG(accel_directives).max_wasted_percentage);
807-
add_assoc_long(&directives, "opcache.consistency_checks", ZCG(accel_directives).consistency_checks);
808793
add_assoc_long(&directives, "opcache.force_restart_timeout", ZCG(accel_directives).force_restart_timeout);
809794
add_assoc_long(&directives, "opcache.revalidate_freq", ZCG(accel_directives).revalidate_freq);
810795
add_assoc_string(&directives, "opcache.preferred_memory_model", STRING_NOT_NULL(ZCG(accel_directives).memory_model));

ext/opcache/zend_file_cache.c

-1
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,6 @@ zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handl
19361936

19371937
if (cache_it) {
19381938
ZCSG(map_ptr_last) = CG(map_ptr_last);
1939-
script->dynamic_members.checksum = zend_accel_script_checksum(script);
19401939
script->dynamic_members.last_used = ZCG(request_time);
19411940

19421941
zend_accel_hash_update(&ZCSG(hash), script->script.filename, 0, script);

php.ini-development

-4
Original file line numberDiff line numberDiff line change
@@ -1841,10 +1841,6 @@ ldap.max_links = -1
18411841
; are cached.
18421842
;opcache.max_file_size=0
18431843

1844-
; Check the cache checksum each N requests.
1845-
; The default value of "0" means that the checks are disabled.
1846-
;opcache.consistency_checks=0
1847-
18481844
; How long to wait (in seconds) for a scheduled restart to begin if the cache
18491845
; is not being accessed.
18501846
;opcache.force_restart_timeout=180

php.ini-production

-4
Original file line numberDiff line numberDiff line change
@@ -1843,10 +1843,6 @@ ldap.max_links = -1
18431843
; are cached.
18441844
;opcache.max_file_size=0
18451845

1846-
; Check the cache checksum each N requests.
1847-
; The default value of "0" means that the checks are disabled.
1848-
;opcache.consistency_checks=0
1849-
18501846
; How long to wait (in seconds) for a scheduled restart to begin if the cache
18511847
; is not being accessed.
18521848
;opcache.force_restart_timeout=180

0 commit comments

Comments
 (0)