-
Notifications
You must be signed in to change notification settings - Fork 7.9k
opcache_is_script_cached_in_file_cache(string $filename) #16979
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
base: master
Are you sure you want to change the base?
Changes from 12 commits
200193b
798a07d
824e638
30641d6
283844e
8cc7293
fd93557
7e23285
906b92d
1cdf3fa
f620d9c
6df1562
e282578
17edbe6
cd0177f
7cff70a
59a4ecc
b3b9501
d1b74e9
1b8311b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--TEST-- | ||
GH-16551: opcache file cache read only: generate file cache | ||
--INI-- | ||
opcache.enable=1 | ||
opcache.enable_cli=1 | ||
opcache.jit=disable | ||
opcache.jit_buffer_size=0 | ||
opcache.file_cache="{TMP}" | ||
--EXTENSIONS-- | ||
opcache | ||
--CONFLICTS-- | ||
opcache_file_cache | ||
--FILE-- | ||
<?php | ||
|
||
$file = __DIR__ . '/gh16551_998.inc'; | ||
$uncached_file = __DIR__ . '/gh16551_999.inc'; | ||
|
||
opcache_compile_file($file); | ||
|
||
var_dump( | ||
opcache_is_script_cached($file) | ||
); | ||
|
||
var_dump( | ||
opcache_is_script_cached_in_file_cache($file) | ||
); | ||
|
||
var_dump( | ||
opcache_is_script_cached($uncached_file) | ||
); | ||
|
||
var_dump( | ||
opcache_is_script_cached_in_file_cache($uncached_file) | ||
); | ||
|
||
?> | ||
--EXPECT-- | ||
bool(true) | ||
bool(true) | ||
bool(false) | ||
bool(false) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--TEST-- | ||
GH-16551: opcache file cache read only: read file cache | ||
--INI-- | ||
opcache.enable=1 | ||
opcache.enable_cli=1 | ||
opcache.jit=disable | ||
opcache.jit_buffer_size=0 | ||
opcache.file_cache="{TMP}" | ||
opcache.file_cache_read_only=1 | ||
--EXTENSIONS-- | ||
opcache | ||
--CONFLICTS-- | ||
opcache_file_cache | ||
--FILE-- | ||
<?php | ||
|
||
$file = __DIR__ . '/gh16551_998.inc'; | ||
$uncached_file = __DIR__ . '/gh16551_999.inc'; | ||
|
||
var_dump( | ||
opcache_is_script_cached_in_file_cache($file) | ||
); | ||
|
||
require $file; | ||
|
||
var_dump( | ||
opcache_is_script_cached_in_file_cache($uncached_file) | ||
); | ||
|
||
require $uncached_file; | ||
|
||
?> | ||
--EXPECT-- | ||
bool(true) | ||
9 | ||
bool(false) | ||
8 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--TEST-- | ||
GH-16551: opcache file cache read only: read file cache with limited checks | ||
--INI-- | ||
opcache.enable=1 | ||
opcache.enable_cli=1 | ||
opcache.jit=disable | ||
opcache.jit_buffer_size=0 | ||
opcache.file_cache="{TMP}" | ||
opcache.file_cache_read_only=1 | ||
opcache.revalidate_freq=0 | ||
opcache.enable_file_override=true | ||
opcache.validate_timestamps=false | ||
opcache.file_cache_consistency_checks=false | ||
--EXTENSIONS-- | ||
opcache | ||
--CONFLICTS-- | ||
opcache_file_cache | ||
--FILE-- | ||
<?php | ||
|
||
$file = __DIR__ . '/gh16551_998.inc'; | ||
$uncached_file = __DIR__ . '/gh16551_999.inc'; | ||
|
||
var_dump( | ||
opcache_is_script_cached_in_file_cache($file) | ||
); | ||
|
||
require $file; | ||
|
||
var_dump( | ||
opcache_is_script_cached_in_file_cache($uncached_file) | ||
); | ||
|
||
require $uncached_file; | ||
|
||
?> | ||
--EXPECT-- | ||
bool(true) | ||
9 | ||
bool(false) | ||
8 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--TEST-- | ||
GH-16551: opcache file cache read only: ensure we can't invalidate | ||
--INI-- | ||
opcache.enable=1 | ||
opcache.enable_cli=1 | ||
opcache.jit=disable | ||
opcache.jit_buffer_size=0 | ||
opcache.file_cache="{TMP}" | ||
opcache.file_cache_read_only=1 | ||
--EXTENSIONS-- | ||
opcache | ||
--CONFLICTS-- | ||
opcache_file_cache | ||
--FILE-- | ||
<?php | ||
|
||
$file = __DIR__ . '/gh16551_998.inc'; | ||
|
||
var_dump( | ||
opcache_is_script_cached_in_file_cache($file) | ||
); | ||
|
||
// invalidate SHM, but silently ignore file cache. | ||
opcache_invalidate($file, true); | ||
|
||
var_dump( | ||
opcache_is_script_cached_in_file_cache($file) | ||
); | ||
|
||
require $file; | ||
|
||
?> | ||
--EXPECT-- | ||
bool(true) | ||
bool(true) | ||
9 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--TEST-- | ||
GH-16551: opcache file cache read only: ensure cache files aren't created | ||
--INI-- | ||
opcache.enable=1 | ||
opcache.enable_cli=1 | ||
opcache.jit=disable | ||
opcache.jit_buffer_size=0 | ||
opcache.file_cache="{TMP}" | ||
opcache.file_cache_read_only=1 | ||
--EXTENSIONS-- | ||
opcache | ||
--CONFLICTS-- | ||
opcache_file_cache | ||
--FILE-- | ||
<?php | ||
|
||
$uncached_file = __DIR__ . '/gh16551_999.inc'; | ||
|
||
// fix problem on ARM where it was already reporting as cached in SHM. | ||
opcache_invalidate($uncached_file); | ||
|
||
var_dump( | ||
opcache_is_script_cached($uncached_file) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit confused: The CircleCI unit test for ARM is failing reliably on this line (it's returning I've added in the call to Is this potentially a bug on ARM? I'll sleep on it and see if I can figure out what's happening tomorrow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't re-create a problem with I've removed the unnecessary tests and re-written the failing test to remove the part causing the issue. |
||
); | ||
|
||
var_dump( | ||
opcache_is_script_cached_in_file_cache($uncached_file) | ||
); | ||
|
||
opcache_compile_file($uncached_file); | ||
|
||
var_dump( | ||
opcache_is_script_cached($uncached_file) | ||
); | ||
|
||
var_dump( | ||
opcache_is_script_cached_in_file_cache($uncached_file) | ||
); | ||
|
||
?> | ||
--EXPECT-- | ||
bool(false) | ||
bool(false) | ||
bool(true) | ||
bool(false) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--TEST-- | ||
GH-16551: opcache file cache read only: double check file_cache_only | ||
--INI-- | ||
opcache.enable=1 | ||
opcache.enable_cli=1 | ||
opcache.jit=disable | ||
opcache.jit_buffer_size=0 | ||
opcache.file_cache="{PWD}" | ||
opcache.file_cache_only=1 | ||
--EXTENSIONS-- | ||
opcache | ||
--CONFLICTS-- | ||
opcache_file_cache | ||
--FILE-- | ||
<?php | ||
|
||
$uncached_file = __DIR__ . '/gh16551_999.inc'; | ||
|
||
var_dump( | ||
opcache_is_script_cached($uncached_file) | ||
); | ||
|
||
var_dump( | ||
opcache_is_script_cached_in_file_cache($uncached_file) | ||
); | ||
|
||
opcache_compile_file($uncached_file); | ||
|
||
var_dump( | ||
opcache_is_script_cached($uncached_file) | ||
); | ||
|
||
// check the cache file itself exists... | ||
if (substr(PHP_OS, 0, 3) !== 'WIN') { | ||
$pattern = __DIR__ . '/*/' . __DIR__ . '/*16551_999.inc.bin'; | ||
} else { | ||
$pattern = __DIR__ . '/*/*/' . str_replace(':', '', __DIR__) . '/*16551_999.inc.bin'; | ||
} | ||
foreach (glob($pattern) as $p) { | ||
var_dump($p !== false); | ||
} | ||
|
||
// check it is reported as existing... | ||
var_dump( | ||
opcache_is_script_cached_in_file_cache($uncached_file) | ||
); | ||
|
||
?> | ||
--CLEAN-- | ||
<?php | ||
if (substr(PHP_OS, 0, 3) !== 'WIN') { | ||
$pattern = __DIR__ . '/*/' . __DIR__ . '/*16551*.bin'; | ||
} else { | ||
$pattern = __DIR__ . '/*/*/' . str_replace(':', '', __DIR__) . '/*16551*.bin'; | ||
} | ||
foreach (glob($pattern) as $p) { | ||
unlink($p); | ||
$p = dirname($p); | ||
while(strlen($p) > strlen(__DIR__)) { | ||
@rmdir($p); | ||
$p = dirname($p); | ||
} | ||
} | ||
?> | ||
--EXPECT-- | ||
bool(false) | ||
bool(false) | ||
bool(false) | ||
bool(true) | ||
bool(true) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
$a = 4+5; | ||
|
||
echo $a . "\n"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
$a = 3+5; | ||
|
||
echo $a . "\n"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--TEST-- | ||
GH-16979: opcache_is_script_cached support file_cache argument | ||
--INI-- | ||
opcache.enable=1 | ||
opcache.enable_cli=1 | ||
opcache.jit=disable | ||
opcache.jit_buffer_size=0 | ||
opcache.file_cache="{TMP}" | ||
--EXTENSIONS-- | ||
opcache | ||
--FILE-- | ||
<?php | ||
|
||
opcache_compile_file(__FILE__); | ||
|
||
var_dump( | ||
opcache_is_script_cached(__FILE__) | ||
); | ||
|
||
var_dump( | ||
opcache_is_script_cached_in_file_cache(__FILE__) | ||
); | ||
|
||
?> | ||
--EXPECT-- | ||
bool(true) | ||
bool(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests look problematic to me. They will fail on first execution (confirmed locally).
I don't understand why they don't fail on CI. It's also possible they are order dependent, i.e. one job will prime the cache, another will check that the cache is not primed.
One solution might be to set
opcache.file_cache
to some sub-directory and clean it in the--CLEAN--
section to ensure a consistent state.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iluuu1994 ,
Yes, they are order dependent - and using the conflict tag means they run one after another, even in parallel mode:
However, I seem to have overlooked the fact that they expect the file-cache to be empty on first run, whereas yours already appears to be populated, potentially from a previous run - it won't be a problem on CI, as they always start with a fresh environment.
I think you are right about using
--CLEAN--
- I'll look into implementing this, thank you!EDIT: actually, no, my mistake - it's already using it's own file cache directly, as:
opcache.file_cache="{TMP}"
{TMP}
should be a single-use temporary directory set up by the scripts that run the testing, so it shouldn't be pre-populated, even if you've run before on the same local machine.We aren't cleaning it, as the script removes the temporary folder when it's finished running anyway.
I'm struggling to tell from your quoted output, but does it appear they are running out-of-order?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, but these tests will still break with
--shuffle
. I think we should make an effort not to make tests order-dependent.{TMP}
simply resolves tosys_get_temp_dir()
, which usually is just/tmp
. So it's not single-use. Actually, we depend on it not being single-use for theOPCACHE_VARIATION
variation job in nightly, which runs test twice, first populating the file cache and then using it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification! I’ll shuffle things around, probably into the same test rather than multiple? And ensure we’re using a folder than is then subsequently cleaned up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind bigger tests if that's easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iluuu1994 , sorry about the delay!
I've refactored the tests following your suggestions, and they should now run in any order, without being interdependent, and support the
OPCACHE_VARIATION
run properly.Do these look any better?
And if you are happy with everything, do you think there is still time for this to potentially make it into PHP 8.5?