Skip to content

Commit f5c200f

Browse files
committed
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: Fixed Issue #140: "opcache.enable_file_override" doesn't respect "opcache.revalidate_freq" opcodes
2 parents ee55edf + 0dcaf0f commit f5c200f

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ static inline int do_validate_timestamps(zend_persistent_script *persistent_scri
877877
return FAILURE;
878878
}
879879

880-
static inline int validate_timestamp_and_record(zend_persistent_script *persistent_script, zend_file_handle *file_handle TSRMLS_DC)
880+
int validate_timestamp_and_record(zend_persistent_script *persistent_script, zend_file_handle *file_handle TSRMLS_DC)
881881
{
882882
if (ZCG(accel_directives).revalidate_freq &&
883883
(persistent_script->dynamic_members.revalidate >= ZCSG(revalidate_at))) {

ext/opcache/ZendAccelerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ extern char *zps_api_failure_reason;
330330
void accel_shutdown(TSRMLS_D);
331331
void zend_accel_schedule_restart(zend_accel_restart_reason reason TSRMLS_DC);
332332
void zend_accel_schedule_restart_if_necessary(zend_accel_restart_reason reason TSRMLS_DC);
333+
int validate_timestamp_and_record(zend_persistent_script *persistent_script, zend_file_handle *file_handle TSRMLS_DC);
333334
int zend_accel_invalidate(const char *filename, int filename_len, zend_bool force TSRMLS_DC);
334335
int zend_accel_script_optimize(zend_persistent_script *persistent_script TSRMLS_DC);
335336
int accelerator_shm_read_lock(TSRMLS_D);

ext/opcache/tests/issue0140.phpt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Issue #140: "opcache.enable_file_override" doesn't respect "opcache.revalidate_freq"
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.revalidate_freq=0
7+
opcache.file_update_protection=0
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
<?php if (php_sapi_name() != "cli") die("skip CLI only"); ?>
11+
--FILE--
12+
<?php
13+
define("FILENAME", dirname(__FILE__) . "/issuer0140.inc.php");
14+
file_put_contents(FILENAME, "1\n");
15+
16+
var_dump(is_readable(FILENAME));
17+
include(FILENAME);
18+
var_dump(filemtime(FILENAME));
19+
20+
sleep(2);
21+
file_put_contents(FILENAME, "2\n");
22+
23+
var_dump(is_readable(FILENAME));
24+
include(FILENAME);
25+
var_dump(filemtime(FILENAME));
26+
27+
sleep(2);
28+
unlink(FILENAME);
29+
30+
var_dump(is_readable(FILENAME));
31+
var_dump(@include(FILENAME));
32+
var_dump(@filemtime(FILENAME));
33+
?>
34+
--EXPECTF--
35+
bool(true)
36+
1
37+
int(%d)
38+
bool(true)
39+
2
40+
int(%d)
41+
bool(false)
42+
bool(false)
43+
bool(false)

ext/opcache/zend_accelerator_module.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,15 @@ static int filename_is_in_cache(char *filename, int filename_len TSRMLS_DC)
313313
if (IS_ABSOLUTE_PATH(filename, filename_len)) {
314314
persistent_script = zend_accel_hash_find(&ZCSG(hash), filename, filename_len + 1);
315315
if (persistent_script) {
316-
return !persistent_script->corrupted;
316+
return !persistent_script->corrupted &&
317+
validate_timestamp_and_record(persistent_script, &handle TSRMLS_CC) == SUCCESS;
317318
}
318319
}
319320

320321
if ((key = accel_make_persistent_key_ex(&handle, filename_len, &key_length TSRMLS_CC)) != NULL) {
321322
persistent_script = zend_accel_hash_find(&ZCSG(hash), key, key_length + 1);
322-
return persistent_script && !persistent_script->corrupted;
323+
return persistent_script && !persistent_script->corrupted &&
324+
validate_timestamp_and_record(persistent_script, &handle TSRMLS_CC) == SUCCESS;
323325
}
324326

325327
return 0;

0 commit comments

Comments
 (0)