-
Notifications
You must be signed in to change notification settings - Fork 125
Improve shutdown callback #367
New issue
Have a question about this project? Sign up for a free GitHub a 8000 ccount 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
Improve shutdown callback #367
Conversation
I like this way of handling that situation. It's probably safer to not cache the page, but there are sites that simply exit early in the process so that wp_query isn't defined (Paul's one is an example), but still want their pages cached. They should define wp_query of course, and maybe this is what the plugin will force users to do in the future, but if there are unmaintained plugins doing this, ordinary users won't have the skills to fix the problem. Will think about this over the weekend. |
In the case of a fatal error I agree that the plugin should not cache the page, but the wp_query object is used by the plugin at the very end of the PHP process, after all WordPress code is supposed to have already run so I don't think there's much danger in creating it in the output buffer callback. It's mostly only used to check if the plugin needs to ignore caching of particular types of pages too, so it's not depending on the WordPress loop or anything complicated. Saying that, I suspect that creating that object will create a blank object where none of the is_* functions return true, but I have yet to test that. |
By all my tests, in 99% (in last few days) it's impossible to find any useful info from wp_query, so your suspicions are legitimate. Also, many plugins use die in action These type of plugins often use I've some PHP scripts which only include From other side, you added code which block caching for unknown types, but later, we fixed caching of sitemaps, I'm thinking that we can add some filter there which enable/disable caching for unknown pages. Or even you can cache it. (it's possible to check is I agree that handling PHP fatal errors are good option and we can add it regardless to WP query. By my testing, it works fine. I've enabled xdebug stack trace on all my websites and I'm trying to catch all PHP warnings/notices. (I've found some minor issues) |
If found PHP notices in debug.log:
I was able way how to reproduce them and find root of cause. I made new commit which also fixes some unnecessary whitespace. If it needs, I can elaborate more about changes. I'm testing it on all websites and I didn't notice new PHP notices except an issue related to is_front_page in WP core (related to https://core.trac.wordpress.org/ticket/30210). |
Thanks for testing that! I agree we will need a filter on the unknown page caching. The debug message should inform the site owner how to enable it too. |
The wpsc_only_cache_known_pages filter returns 1 so that unknown page types are not cached. If the filter returns 0 even unknown page types will be cached, if all other conditions for caching are satisfied.
I added the filter "wpsc_only_cache_known_pages" to your PR. That should let site owners cache these types of pages. |
Thanks for filter! You are welcome 😃 I added is_404 into wp_super_cache_query_vars because |
I'm hoping to make a new release today in the next 5 hours. It would be great to have this PR in there but otherwise it can wait until the next one. I think it looks ok, but will wait for your testing. The non-caching of fatal errors is enough for a new point release in a week if we need more time. |
Based on your checking of So, we should merge this PR. If we need to fix something else, we will create new PR. |
Summary
There are two cases when shutdown callback is executed too early:
This PR is introducing function wpsc_is_fatal_error which uses error_get_last and stop caching.
Also, if output buffer is empty or main query doesn't exist then prevents calling
wp_super_cache_query_vars
.Test instructions