-
Notifications
You must be signed in to change notification settings - Fork 8k
opcache_is_script_cached() honors preloaded scripts #7300
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
Conversation
a990805 to
7387f56
Compare
|
Any chance this'll get a review pre-8.1RC1? |
|
It looks like we have a different problem. I suppose, this should be fixed in a different way. Using zend_resolve_path(). diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c
index da1696bb92..4822c5b8a8 100644
--- a/ext/opcache/zend_accelerator_module.c
+++ b/ext/opcache/zend_accelerator_module.c
@@ -307,11 +307,12 @@ ZEND_INI_END()
static int filename_is_in_cache(zend_string *filename)
{
- zend_string *key;
+ zend_string *key = zend_resolve_path(filename);
- key = accel_make_persistent_key(filename);
if (key != NULL) {
zend_persistent_script *persistent_script = zend_accel_hash_find(&ZCSG(hash), key);
+
+ zend_string_release(key);
if (persistent_script && !persistent_script->corrupted) {
if (ZCG(accel_directives).validate_timestamps) {
zend_file_handle handle;@nikic do you see any problems? |
|
@dstogov I'm not really familiar with path handling in opcache. Maybe this will cause performance regressions for file_override_enabled, as it will now try to realpath resolve the path? |
|
@nikic good point. It's better to keep the old behavior for file_override_enabled. Like this: diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c
index da1696bb92..379c68e188 100644
--- a/ext/opcache/zend_accelerator_module.c
+++ b/ext/opcache/zend_accelerator_module.c
@@ -305,13 +305,17 @@ ZEND_INI_BEGIN()
#endif
ZEND_INI_END()
-static int filename_is_in_cache(zend_string *filename)
+static int filename_is_in_cache(zend_string *filename, bool use_realpath)
{
zend_string *key;
- key = accel_make_persistent_key(filename);
+ key = use_realpath ? zend_resolve_path(filename) : accel_make_persistent_key(filename);
if (key != NULL) {
zend_persistent_script *persistent_script = zend_accel_hash_find(&ZCSG(hash), key);
+
+ if (use_realpath) {
+ zend_string_release(key);
+ }
if (persistent_script && !persistent_script->corrupted) {
if (ZCG(accel_directives).validate_timestamps) {
zend_file_handle handle;
@@ -337,7 +341,7 @@ static int accel_file_in_cache(INTERNAL_FUNCTION_PARAMETERS)
zval *zv = ZEND_CALL_ARG(execute_data , 1);
if (Z_TYPE_P(zv) == IS_STRING && Z_STRLEN_P(zv) != 0) {
- return filename_is_in_cache(Z_STR_P(zv));
+ return filename_is_in_cache(Z_STR_P(zv), 0);
}
}
return 0;
@@ -921,5 +925,5 @@ ZEND_FUNCTION(opcache_is_script_cached)
RETURN_FALSE;
}
- RETURN_BOOL(filename_is_in_cache(script_name));
+ RETURN_BOOL(filename_is_in_cache(script_name, 1));
} |
|
@m6w6 does the last patch above solve the problem? |
|
@dstogov no, maybe there's a misunderstanding. The problem is that during preloading, one cannot check whether a specific file has already been preloaded.
That said, I'd be fine with a separate |
|
I see. This is completely different problem and you are the first who asked for this feature. Can you describe what you are doing. In worst case it's better to introduce @nikic FYI |
|
@dstogov, I guess one would need to wrap the autoloader (which nowadays is usually composer) |
|
During preloading autoloader should behave in the same way as usually. Composer doesn't use Please, describe your scenario and problem. |
|
Okay, imagine you've got a list from opcache status, which files make most sense to preload, which is separated into a list to just In either way, I cannot ask PHP if a file has already been preloaded. I think it's a simple requirement and initially thought |
|
If we introduce See alternative implementation #7435 I'm not a fun of introducing new internal function for every possible scenario. Instead of using I'm also not sure if it's possible to introduce internal function after feature freeze. |
I still don't really get under what circumstances you could end up with an already preloaded file. Does your list of preloading candidates contain duplicates? |
|
I think it's a legitimate question to ask whether a file has been preloaded, as it is to ask whether a file has already been op-cached. I would have been fine if NB: Looks like using |
|
On Thu, Sep 2, 2021 at 9:51 AM Michael Wallner ***@***.***> wrote:
I think it's a legitimate question to ask whether a file has been
preloaded, as it is to ask whether a file has already been op-cached.
At request time, you can get information about preloaded files through
opcache_get_status(true).
During preloading this information is not available, because the preloading
wasn't finished yet.
I would have been fine if opcache_is_script_cached had answered this
question while preloading without distinguishing between opcached and
preloaded, but I'd also be fine with #7435
<#7435>, which clearly is a lot more
sophisticated.
This PR implements what you probably need, but I still didn't understand
the use-case.
NB: Looks like using opcache_compile_file for preloading is not working
as well as require anyway: https://github.com/m6w6/test-php-preload
Yeah. There is a problem with circular class dependencies.
Nikita, can you please take a look.
Thanks. Dmitry.
… —
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#7300 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AATEZUV62JQD2O7FM4C6RNTT74NIBANCNFSM5A3WHUCA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
This issue is fixed in PHP 8.1 already. Unresolved initializers no longer prevent opcache_compile_file() preloading. |
ACK, can confirm: https://github.com/m6w6/test-php-preload/actions/runs/1212844178 Closing in favor of #7435 |
opcache_is_script_cachedcurrently ignores preloaded scripts.