Skip to content

Commit f4ab494

Browse files
Mikhail Galaniniluuu1994
Mikhail Galanin
authored andcommitted
Invalidate path even if the file was deleted
Closes GH-12323
1 parent 54452b4 commit f4ab494

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

NEWS

+3
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

+7-2
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,7 @@ int zend_accel_invalidate(zend_string *filename, bool force)
13221322
{
13231323
zend_string *realpath;
13241324
zend_persistent_script *persistent_script;
1325+
zend_bool file_found = true;
13251326

13261327
if (!ZCG(accelerator_enabled) || accelerator_shm_read_lock() != SUCCESS) {
13271328
return FAILURE;
@@ -1330,7 +1331,10 @@ int zend_accel_invalidate(zend_string *filename, bool force)
13301331
realpath = accelerator_orig_zend_resolve_path(filename);
13311332

13321333
if (!realpath) {
1333-
return FAILURE;
1334+
//file could have been deleted, but we still need to invalidate it.
1335+
//so instead of failing, just use the provided filename for the lookup
1336+
realpath = zend_string_copy(filename);
1337+
file_found = false;
13341338
}
13351339

13361340
if (ZCG(accel_directives).file_cache) {
@@ -1366,12 +1370,13 @@ int zend_accel_invalidate(zend_string *filename, bool force)
13661370

13671371
file_handle.opened_path = NULL;
13681372
zend_destroy_file_handle(&file_handle);
1373+
file_found = true;
13691374
}
13701375

13711376
accelerator_shm_read_unlock();
13721377
zend_string_release_ex(realpath, 0);
13731378

1374-
return SUCCESS;
1379+
return file_found ? SUCCESS : FAILURE;
13751380
}
13761381

13771382
static zend_string* accel_new_interned_key(zend_string *key)
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)