Minnur.

I was looking for my cache issues today, and could not solve it without disabling the caching.
So open an issue, perhaps somebody else has same setup or any hints regarding this.

Problem:
We are using memcache on the live server, which seems to make troubles with the ads redirect.
It always works 1 time, then you will just receive the node with the title "Redirect Ads".
When I clear cache, it will work for 1 time again, then it fails back to the redirect ads node page.

I see some different things but not yet sure how to fix this.
Its also something between a cache problem and the way we call the redirection in this module. Perhaps this is the problem.

Possible solutions?:
Disabling caching will solve the problem -> not nice idea :)
Extend the "header()"-redirect with some javascript or other ways to redirect
Find a way to not cache this pages, but I didn't could solve this with this memcache setup

I will try to use some javascript or similar for a workaround, lets see...

Regards Cyclodex

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

minnur’s picture

Hi have you tried this module? http://drupal.org/project/cacheexclude

Cyclodex’s picture

Yes but it looks like this can not influence the state, perhaps because I read that you have to set this var:
$conf['page_cache_invoke_hooks'] = false;

No idea, its a bit a complex material for me :)

Now I am also trying to use some other redirects, but somehow when used with the remote tracking url it still failes. Funny is, when I refresh the page then, it redirects... strange.

Some different redirects i am testing :

        if (user_access('count ad clicks') && !_simpleads_bot_detect()) {
          _simpleads_save_click($node);
        }
        $url = _simpleads_validate_url($url);
        
        // Trying to fix some cache problems with memcache.

        header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
        header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
        header("refresh: 5; Location: " . $url);

        drupal_goto($url);
        drupal_exit($url);

Perhaps still some mistakes in my code...

minnur’s picture

Do you also use Varnish ? If yes you could try to exclude the following path from caching:

simpleads/redirect/*

simpleads/load/*/*

Cyclodex’s picture

Yea also using varnish but this one is related to memcache, because our office is ignored by varnish.
Anyway asked our hosting provider to exclude this from the varnish.

I have no clue what goes wrong finally, it is a bit strange, but this code here, makes the redirect working fine without any cache change. The things I tried above seems not really working all the times.

Here I have now a final fallback, with javascript if the header stuff is not working.

Looks fine now, not sure if we want to apply this patch to your module? Please test it for your setup or give me a comment what you think about it:

      else {
        if (user_access('count ad clicks') && !_simpleads_bot_detect()) {
          _simpleads_save_click($node);
        }
        $url = _simpleads_validate_url($url);

        // Set a message that we are redirecting, for behaviours when the node will be shown instead of redirect
        drupal_set_message("Redirecting to: " . $url, 'status');

        // Trying to fix the memcache problem, not redirecting sometimes
        header("Location: " . $url);
        header( "refresh:0;url=".$url, false);

        // Fallback if header redirection did not work, try it with javascript
        drupal_add_js('jQuery(document).ready(function () { document.location = "'.$url.'"; });',
          array('type' => 'inline', 'scope' => 'footer', 'weight' => 0)
        );
      }

We could improve it further, make the URL in the message also a link etc.
Just want to hear your feedback first. And I don't know yet how to provide a patch, I will have to read up how that should be done correctly.

minnur’s picture

Hi Cyclodex,

Thanks for the code. I will review it, this is more like workaround.
We are launching the site on server Varnish+memcached very soon and most likely we will get this problem too.
I will try to come up with some solution (maybe I will implement my own hook that will alter default redirection behavior) so it will be alterable without actually hacking the SimpleAds module.

Thanks,

Minnur

minnur’s picture

Hi Cyclodex,

I just added a new hook, please get the latest code from GIT.

hook_simpleads_redirect($url, $delta);

Here is how to use your code with SimpleAds:

<?php
/**
 * Implements hook_simpleads_redirect().
 */
function YOURMODULE_simpleads_redirect($url, $delta) {
  if ($delta == 'YOUR_DELTA') {
    // Set a message that we are redirecting, for behaviours when the node will be shown instead of redirect
    drupal_set_message("Redirecting to: " . $url, 'status');
    // Trying to fix the memcache problem, not redirecting sometimes
    header("Location: " . $url);
    header( "refresh:0;url=" . $url, false);

    // Fallback if header redirection did not work, try it with javascript
    drupal_add_js('jQuery(document).ready(function () { document.location = "' . $url . '"; });',
      array('type' => 'inline', 'scope' => 'footer', 'weight' => 0)
    );
  }
}
?>

Please use the following variable to set the delta:
variable_set('simpleads_redirect_delta', 'YOUR_DELTA');

Thanks

minnur’s picture

FYI, I just release SimpleAds version 7.x-1.8.

Cyclodex’s picture

Thanks minnur!

Great to use this hook.
I wanted to update your code and it looks ok ,but the only problem I see is, the Ads I already have setup are now all empty... They just loosed their data somehow.

Can you try out if that also happens for you?

When I create a new one, it looks ok
But is there a problem/bug or why are my old Ads not complete anymore ?
They just have the title and language selected, but no ad group, active date, image or other settings...

Strange, I don't see any code change which could made this problems.
Hmm otherwise I will just recreate them...

Angry Dan’s picture

Rather than using a hook to pass out the cache circumvention work to a custom module, would it not be better to always disable caching on the redirect pages? This would also ensure that clicks are properly registered.

See attached patch, I think this should resolve the issue.

minnur’s picture

@Cyclodex, any updates ? Were you able to identify the problem with the update ?

Thanks

Cyclodex’s picture

Hey
Did not know this option, but hope this works fine :)

I also implemented this option but I think I still left my fallbacks in for the moment.
Because we only have this setup on "live"-platform I can't make any tests so. And because we don't want to break the counts on the already implemented ads I can't do for the moment.
Would have to need some more time to test and have a look why this all happens. Sorry
Just having to much other project tasks to do :-/

Nobody else using this memcache with SimpleAds?

MrPeanut’s picture

I've noticed this issue with SimpleAds using Boost. I had to disable Boost for now, but may try excluding the simpleads/redirect paths.

I may also try Ajax Blocks.

minnur’s picture

Assigned: Unassigned » minnur
Status: Active » Needs work
21tech’s picture

I am using boost and simply disable the cache on simpleads/* pages and all seems to be fine.

I do not remember if block caching stops rotation, but if it does I would recommend block_cache_alter module.

cimo75’s picture

Hi I had to enable the cacheexclude module to get simpleads to show properly, otherwise they would randomly appear, disappear.
Now I ve found out that simpleads will show up only on mydomain.com and not in www.mydomain.com, how can i fix that? For the moment I ll force a redirect to my domian without www prefix.
Simone

johnnybgoode’s picture

I was having problems with the redirect page being cached when switching between http and https, and can confirm that the patch in #9 worked for me.

minnur’s picture

Please try to add this function to page callback: http://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupa...

minnur’s picture

I disabled caching in simpleads/redirect/* paths . Please download dev version and test.

Thanks!

Angry Dan’s picture

Wow, that's even cooler, I hadn't seen that function before.

Will use that in future

tmsimont’s picture

Status: Needs work » Reviewed & tested by the community

thanks @minnur -- adding drupal_page_is_cacheable(FALSE); looks like it did the trick.

Pete B’s picture

I have confirmed this solution too. Can we get a stable release please?

josean’s picture

I also confirm, #9 patch from Angry Dan works in my site, running 7.x-1.8.

Many thanks!

david_garcia’s picture

I also confirm, #9 patch from Angry Dan works in my site.

Many thanks!

mrmikedewolf’s picture

Version: 7.x-1.7 » 7.x-1.x-dev
Status: Needs work » Reviewed & tested by the community
FileSize
555 bytes

For anyone stuck on simpleads v. 7.x-1.7, here is a version of the patch from #9 that they can use.

I mistakenly put the wrong version in the dropdown for version so this may fail testing. It is for 7.x-1.7.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, simpleads-prevent-redirect-caching-1555988-24.patch, failed testing.

mrmikedewolf’s picture

Version: 7.x-1.x-dev » 7.x-1.7
FileSize
557 bytes

Here is a patch for 7.x-1.7 that implements minnur's fix from #17.

Clint Eagar’s picture

Version: 7.x-1.x-dev » 7.x-1.7
Status: Reviewed & tested by the community » Needs work

Confirming #9 works for me, using Simpleads D7 1.8 and Xcache.

skyredwang’s picture

Version: 7.x-1.7 » 7.x-1.x-dev
Issue summary: View changes
Status: Needs work » Reviewed & tested by the community

Patch should be always agaisnt HEAD

Dimm’s picture

Boost+SimpleAds 7.x-1.8 = redirect problem.
I disabled caching in simpleads/redirect/* paths .
And uncheck admin/config/system/boost/debug
"Send debug info for each request to watchdog."
OK!!!

nicxvan’s picture

#9 worked for me in 1.8

nicxvan’s picture

Can we get this committed?

aharown07’s picture

Status: Reviewed & tested by the community » Postponed

oops

aharown07’s picture

Status: Postponed » Fixed

This appears to be fixed in 1.9. I was seeing the issue in 1.8 but not at all since going to 1.9

JordanMagnuson’s picture

Yes, this is fixed in 1.9.

Status: Fixed » Closed (fixed)

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