Open ethanpil opened 9 years ago
Thanks for the report @ethanpil. I'm marking this as "needs testing" so that one of us can take a closer look at trying to resolve this. If you find out more, please do share that with us here.
Reproduced this issue:
</html>
<!-- Comet Cache file path: /cache/comet-cache/cache/https/wp-vm/category/uncategorized.u/1.html -->
<!-- Comet Cache file built for (https://wp.vm/category/uncategorized/; user token: 1) in 0.63581 seconds, on: May 12th, 2016 @ 4:04 pm UTC. -->
<!-- This Comet Cache file will auto-expire (and be rebuilt) on: May 19th, 2016 @ 4:04 pm UTC (based on your configured expiration time). -->
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- Comet Cache fully functional :-) Cache file served for (https://wp.vm/category/uncategorized/; user token: 1) in 0.55092 seconds, on: May 12th, 2016 @ 4:04 pm UTC. -->
Warning: Cannot modify header information - headers already sent by (output started at /vagrant/src/app/src/wp-content/plugins/comet-cache-pro/src/includes/traits/Ac/PostloadUtils.php:202) in /vagrant/src/app/src/wp-content/plugins/wp-session-manager-master/includes/class-wp-session.php on line 128
The session plugin uses a shutdown function to write the cookie.
After this line add the following:
if(defined('WP_SESSION_COOKIE')) {
$regex_logged_in_cookies .= '|'.preg_quote(WP_SESSION_COOKIE, '/');
} else {
$regex_logged_in_cookies .= '|_wp_session';
}
After this bracket add the following:
elseif (!empty($_COOKIE[defined('WP_SESSION_COOKIE') ? WP_SESSION_COOKIE : '_wp_session'])) {
$wp_session_cookie = stripslashes($_COOKIE[defined('WP_SESSION_COOKIE') ? WP_SESSION_COOKIE : '_wp_session']]);
$wp_session_cookie_crumbs = explode('||', $wp_session_cookie);
return $token = preg_replace('/[^a-z0-9]/i', '', (string) $cookie_crumbs[0]);
}
Before this line add the following:
if (has_action('shutdown', 'wp_session_write_close')) { // Trying to write cookies during shutdown?
remove_action('shutdown', 'wp_session_write_close'); // Disable & trigger it now.
wp_session_write_close(); // See: <https://github.com/ericmann/wp-session-manager>
}
When this plugin is running and a session is established, CC needs to consider the current user as being like any user who is currently logged into the site or like a commenter; i.e., any user with a session is likely to be associated with dynamic content that depends on session data. By parsing the session ID we can treat this like any other user and create a user-specific cache for them. Assuming that user-specific caching is enabled in your CC configuration options.
Regardless, the error that I reproduced is caused by this plugin attempting to set a cookie in the WordPress shutdown
phase. That seems like a bug in this plugin, perhaps spotlighted by the fact that Comet Cache is exiting the script before the instance is created and a cookie is set, which would not be expected to occur in the same order in a clean WordPress installation.
To circumvent this we detach the shutdown
hook and trigger the shutdown hook ourselves right before exiting the script and serving a cached copy of the page.
I suggest leaving this issue open and/or forking it into another when this is done. We could look at doing a deeper integration with this plugin in the future; e.g., it would be nice to clear the user-specific cache when session data happens to change.
I am running the latest versions of both WP-Session and QuickCache
https://github.com/ericmann/wp-session-manager
It seems that one of the two plugins is jumping the gun on the cookies in HTTP header...
I keep getting:
: Cannot modify header information - headers already sent by (output started at /srv/public_html/wp-content/advanced-cache.php:1137) in /srv/public_html/wp-content/plugins/wp-session-manager/includes/class-wp-session.php