Skip to content

Commit 6274970

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Invalidate path even if the file was deleted
2 parents 101bd1b + f4ab494 commit 6274970

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ PHP NEWS
3737
. Fixed bug GH-12297 (PHP Startup: Invalid library (maybe not a PHP library)
3838
'mysqlnd.so' in Unknown on line). (nielsdos)
3939

40+
- Opcache:
41+
. Fixed opcache_invalidate() on deleted file. (mikhainin)
42+
4043
- PCRE:
4144
. Fixed bug GH-11956 (Backport upstream fix, PCRE regular expressions with
4245
JIT enabled gives different result). (nielsdos)

ext/opcache/ZendAccelerator.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,7 @@ int zend_accel_invalidate(zend_string *filename, bool force)
13991399
{
14001400
zend_string *realpath;
14011401
zend_persistent_script *persistent_script;
1402+
zend_bool file_found = true;
14021403

14031404
if (!ZCG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
14041405
return FAILURE;
@@ -1407,7 +1408,10 @@ int zend_accel_invalidate(zend_string *filename, bool force)
14071408
realpath = accelerator_orig_zend_resolve_path(filename);
14081409

14091410
if (!realpath) {
1410-
return FAILURE;
1411+
//file could have been deleted, but we still need to invalidate it.
1412+
//so instead of failing, just use the provided filename for the lookup
1413+
realpath = zend_string_copy(filename);
1414+
file_found = false;
14111415
}
14121416

14131417
if (ZCG(accel_directives).file_cache) {
@@ -1432,12 +1436,13 @@ int zend_accel_invalidate(zend_string *filename, bool force)
14321436

14331437
file_handle.opened_path = NULL;
14341438
zend_destroy_file_handle(&file_handle);
1439+
file_found = true;
14351440
}
14361441

14371442
accelerator_shm_read_unlock();
14381443
zend_string_release_ex(realpath, 0);
14391444

1440-
return SUCCESS;
1445+
return file_found ? SUCCESS : FAILURE;
14411446
}
14421447

14431448
static zend_string* accel_new_interned_key(zend_string *key)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
opcache_invalidate() should invalidate deleted file
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable_cli=1
7+
opcache.validate_timestamps=0
8+
--FILE--
9+
<?php
10+
11+
$file = __DIR__ . DIRECTORY_SEPARATOR . pathinfo(__FILE__, PATHINFO_FILENAME) . '.inc';
12+
file_put_contents($file, <<<PHP
13+
<?php
14+
return 42;
15+
PHP);
16+
var_dump(include $file);
17+
unlink($file);
18+
var_dump(include $file);
19+
opcache_invalidate($file);
20+
var_dump(@(include $file));
21+
22+
?>
23+
--EXPECT--
24+
int(42)
25+
int(42)
26+
bool(false)

0 commit comments

Comments
 (0)