Skip to content

Instantly share code, notes, and snippets.

@tony2001
Created November 6, 2020 09:44
Show Gist options
  • Save tony2001/6646c30001194cda1fdd61f494def1e1 to your computer and use it in GitHub Desktop.
Save tony2001/6646c30001194cda1fdd61f494def1e1 to your computer and use it in GitHub Desktop.
commit 222d3cfbaf0a5575a8796838290be2be9d2548a1
Author: Antony Dovgal <tony2001@php.net>
Date: Mon Nov 2 21:24:21 2020 +0300
force file revalidation in long running CLI scripts
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index ee565aa6d0..54ed2a572c 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -1092,14 +1092,35 @@ int validate_timestamp_and_record(zend_persistent_script *persistent_script, zen
{
if (persistent_script->timestamp == 0) {
return SUCCESS; /* Don't check timestamps of preloaded scripts */
- } else if (ZCG(accel_directives).revalidate_freq &&
- persistent_script->dynamic_members.revalidate >= ZCG(request_time)) {
- return SUCCESS;
- } else if (do_validate_timestamps(persistent_script, file_handle) == FAILURE) {
- return FAILURE;
+ }
+
+ if (ZCG(cli_mode)) {
+ struct timeval tp = {0};
+
+ //check current time as opposed to the "time of request"
+ if (gettimeofday(&tp, NULL) != 0) {
+ return SUCCESS;
+ }
+
+ double now = (double)(tp.tv_sec + tp.tv_usec / 1000000.00);
+
+ if (ZCG(accel_directives).revalidate_freq && persistent_script->dynamic_members.revalidate >= now) {
+ return SUCCESS;
+ } else if (do_validate_timestamps(persistent_script, file_handle) == FAILURE) {
+ return FAILURE;
+ } else {
+ persistent_script->dynamic_members.revalidate = now + ZCG(accel_directives).revalidate_freq;
+ return SUCCESS;
+ }
} else {
- persistent_script->dynamic_members.revalidate = ZCG(request_time) + ZCG(accel_directives).revalidate_freq;
- return SUCCESS;
+ if (ZCG(accel_directives).revalidate_freq && persistent_script->dynamic_members.revalidate >= ZCG(request_time)) {
+ return SUCCESS;
+ } else if (do_validate_timestamps(persistent_script, file_handle) == FAILURE) {
+ return FAILURE;
+ } else {
+ persistent_script->dynamic_members.revalidate = ZCG(request_time) + ZCG(accel_directives).revalidate_freq;
+ return SUCCESS;
+ }
}
}
@@ -2565,6 +2586,7 @@ static inline int accel_find_sapi(void)
if (ZCG(accel_directives).enable_cli && (
strcmp(sapi_module.name, "cli") == 0
|| strcmp(sapi_module.name, "phpdbg") == 0)) {
+ ZCG(cli_mode) = 1;
return SUCCESS;
}
}
diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h
index c2f95d7c41..810c8e8ff9 100644
--- a/ext/opcache/ZendAccelerator.h
+++ b/ext/opcache/ZendAccelerator.h
@@ -227,6 +227,7 @@ typedef struct _zend_accel_globals {
/* preallocated buffer for keys */
int key_len;
char key[MAXPATHLEN * 8];
+ zend_bool cli_mode;
} zend_accel_globals;
typedef struct _zend_string_table {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment