Skip to content

opcache: fix revalidation in long running CLI scripts #18671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: PHP-8.3
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify the logic and fix Windows build
  • Loading branch information
Sannis committed May 27, 2025
commit eaa7380287a512d13d598fc2ff69bc11d3ba228c
45 changes: 24 additions & 21 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ typedef int gid_t;
#endif
#include <fcntl.h>
#include <signal.h>

#ifndef PHP_WIN32
#include <time.h>
#else
#include "win32/time.h"
#endif

#ifndef ZEND_WIN32
# include <sys/types.h>
Expand Down Expand Up @@ -1164,33 +1169,31 @@ zend_result validate_timestamp_and_record(zend_persistent_script *persistent_scr
return SUCCESS; /* Don't check timestamps of preloaded scripts */
}

double revalidate_reference_time = 0.0;

if (ZCG(cli_mode)) {
#if HAVE_GETTIMEOFDAY
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;
if (UNEXPECTED(gettimeofday(&tp, NULL) != 0)) {
revalidate_reference_time = (double)time(NULL);
} else {
persistent_script->dynamic_members.revalidate = now + ZCG(accel_directives).revalidate_freq;
return SUCCESS;
revalidate_reference_time = (double)(tp.tv_sec + tp.tv_usec / 1000000.00);
}
#else
revalidate_reference_time = (double)time(NULL);
#endif
} 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;
} else {
persistent_script->dynamic_members.revalidate = ZCG(request_time) + ZCG(accel_directives).revalidate_freq;
return SUCCESS;
}
revalidate_reference_time = (double)ZCG(request_time);
}

if (ZCG(accel_directives).revalidate_freq && persistent_script->dynamic_members.revalidate >= revalidate_reference_time) {
return SUCCESS;
} else if (do_validate_timestamps(persistent_script, file_handle) == FAILURE) {
return FAILURE;
} else {
persistent_script->dynamic_members.revalidate = revalidate_reference_time + ZCG(accel_directives).revalidate_freq;
return SUCCESS;
}
}

Expand Down