wpsharks / comet-cache

An advanced WordPress® caching plugin inspired by simplicity.
https://cometcache.com
GNU General Public License v3.0
76 stars 17 forks source link

Compatibility With WP-SESSION plugin #415

Open ethanpil opened 9 years ago

ethanpil commented 9 years ago

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

jaswrks commented 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.

jaswrks commented 8 years ago

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
jaswrks commented 8 years ago

The session plugin uses a shutdown function to write the cookie.

Referencing: https://github.com/ericmann/wp-session-manager/blob/c446c85909206345d875297d8691396e0ba624a3/includes/wp-session.php#L119

jaswrks commented 8 years ago

Next Actions

Rationale

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.

jaswrks commented 8 years ago

Future Enhancement

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.