Hello,
On my website all pages are cached. After posting a comment, all cached pages are invalidated for current anonymous user. Does this module sets some kind of session or cookie to prevent this? Is it possible to fix this? Thank you for suggestions.

Comments

flocondetoile’s picture

I have the same problem. I use nginx with microcaching and if an anonymous user post a comment, then a cookie SESS is store in the browser and then all pages are no longer cached.

A workaround is to cache the pages for the authenticated users too (who have the SESSION cookie) but not really satisfactory.

The same problem must also occur with Varnish in front of the site.

flocondetoile’s picture

I disabled Ajax comment module and cookies session are always store in the browser.

It seems then that the cookie is stored by an another module

@loparr : have you the module comment notify installed ?

loparr’s picture

Exactly that hapened to me. Session now is stored ALLWAYS, no matter what. I ended up recreating whole new site. Comments now works without creating session if you do not use ajax comments module. So the problem must have been in some other module but I do not want to find it by turning on and off every single module.
No I do not use comment notify. Instead I use simple rules for sending email to admin.

flocondetoile’s picture

I tested on a new drupal site installation, with only ajax comment.

It seems that the drupal session cookie is well in fact generated and stored by Ajax Comment. On this new site, when i disabled it, the session cookie is no longer stored.

But i don't understand why on my site, when i disable ajax comment, the session cookie is always stored in my browser. I clear the cache, uninstall the module, etc without effects.

Edit : in fact, the session cookie is deleted after 10 minutes

loparr’s picture

I tracked this problem to flush page cache module see here http://drupal.org/node/1925398

flocondetoile’s picture

StatusFileSize
new1.82 KB

Hello,

Here is the status of my research and testing on this problem

1 - On a fresh install of Drupal, no module installed, submission of comments does not create cookie
2 - Ajax_comment creates a session cookie when activated
3 - After the module is disabled, session cookies continue to be created after submitting comment

For point 3
In fact a session cookie is created if the parameter (configuration / performance) miminum Cache lifetime is set to a time value. The session cookie is deleted after the time set in this parameter. This should be a normal behavior Drupal ? (which I had not noticed, but this is the first time I use Nginx microcache in front of my site Drupal)

For point 2, I don't know if it is an obligation or behavior that you can change if you want to use Ajax_Comment without using a session cookie.

In my case, I use nginx with microcache set to 60s. If it's necessary to keep the session cookie for Ajax_comments, then the ideal would be to set, with the module settings, the expiration time of the session cookie. For example 60s.

With this setting, when an anonymous visitor post a comment, he gets a session cookie for a period of 60s, and then can see his comment on the page because with the session cookie he bypass the cache nginx (or varnish). After this time, the cookie is deleted and then the visitor gets the cached page, but this page will be regenerated as the microcache is set to 60s.

Attached a patch (this is my first patch, be indulgent;-)) that implements this functionality (on only function submit a comment)

@Loparr : in my case I do not use flush page cache module.

olli’s picture

Category: support » bug
Status: Active » Needs review
StatusFileSize
new776 bytes

@flocondetoile: I skimmed through the code and did not see a point where it should set a session, but noticed a bug when it tries to remove messages from session.

muschpusch’s picture

There was some code which passed a value by SESSION to a function but that is removed a while ago...

olli’s picture

Hi @muschpusch,

I dont know if that could be related since I tried this with a fresh clone.

Current code removes all status messages if any of those three messages are found, but it leaves an empty messages array in $_SESSION. After applying the patch, only those three messages are removed and $_SESSION is cleaned up.

muschpusch’s picture

Status: Needs review » Needs work

Could you use drupal_get_messages instead of the two if's?

olli’s picture

Thanks for the review.

Could you use drupal_get_messages instead of the two if's?

Do you mean these two?

+++ b/ajax_comments.module
@@ -568,7 +568,13 @@ function ajax_comments_remove_status() {
+  if (empty($_SESSION['messages']['status'])) {
+    unset($_SESSION['messages']['status']);
+    if (empty($_SESSION['messages'])) {
+      unset($_SESSION['messages']);

I don't know how to do that with drupal_get_messages().

muschpusch’s picture

Hey, it's easier than you think :)

drupal_get_messages($type = 'status');

Here is what drupal_get_message does (more or less the same if / if code you had)

function drupal_get_messages($type = NULL, $clear_queue = TRUE) {
  if ($messages = drupal_set_message()) {
    if ($type) {
      if ($clear_queue) {
        unset($_SESSION['messages'][$type]);
      }
      if (isset($messages[$type])) {
        return array($type => $messages[$type]);
      }
    }
    else {
      if ($clear_queue) {
        unset($_SESSION['messages']);
      }
      return $messages;
    }
  }
  return array();
}
olli’s picture

Here is what drupal_get_message does (more or less the same if / if code you had)

Please, correct me if I'm wrong about this. That function would clear/unset the messages unconditionally while we want to clean up only if we've unset the last status message (in the foreach loop above our if/if code), right?

muschpusch’s picture

Status: Needs work » Fixed

Sorry i was confused... Your patch got committed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.