Skip to content

Commit e044442

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Invalidate path even if the file was deleted
2 parents 234648e + 520fc70 commit e044442

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,7 @@ zend_result zend_accel_invalidate(zend_string *filename, bool force)
13911391
{
13921392
zend_string *realpath;
13931393
zend_persistent_script *persistent_script;
1394+
zend_bool file_found = true;
13941395

13951396
if (!ZCG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
13961397
return FAILURE;
@@ -1399,7 +1400,10 @@ zend_result zend_accel_invalidate(zend_string *filename, bool force)
13991400
realpath = accelerator_orig_zend_resolve_path(filename);
14001401

14011402
if (!realpath) {
1402-
return FAILURE;
1403+
//file could have been deleted, but we still need to invalidate it.
1404+
//so instead of failing, just use the provided filename for the lookup
1405+
realpath = zend_string_copy(filename);
1406+
file_found = false;
14031407
}
14041408

14051409
if (ZCG(accel_directives).file_cache) {
@@ -1424,12 +1428,13 @@ zend_result zend_accel_invalidate(zend_string *filename, bool force)
14241428

14251429
file_handle.opened_path = NULL;
14261430
zend_destroy_file_handle(&file_handle);
1431+
file_found = true;
14271432
}
14281433

14291434
accelerator_shm_read_unlock();
14301435
zend_string_release_ex(realpath, 0);
14311436

1432-
return SUCCESS;
1437+
return file_found ? SUCCESS : FAILURE;
14331438
}
14341439

14351440
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)