Support » Plugin: Ad Inserter - WordPress Ads Management » Plugin Generates Cookies, Breaks Caching?

  • Resolved adinamichelle

    (@adinamichelle)


    Hi there,

    I’ve been using your plugin on my sites hosted with Bluehost for quite some time, but recently migrated to Pagely for hosting. After Pagely migrated my sites with the Ad-Inserter plugin they emailed me the following,

    “It looks like each site is generating cookies. Any plugin or theme that creates a PHP session/cookie will break caching with either present. What that means is that potentially, a single page could have different content for each visitor and it would be dangerous to generate a page once and then serve it from cache to two different visitors. Thus, every single page request would not be cached and consume resources. Both sites look to be using the ad-inserter plugin and that plugin is creating the cookies. I would suggest you contact the plugin dev to see if those can be removed so your sites can work optimally at scale.”

    I went through the FAQ for Ad-Inserter and made sure that none of the following applied to my sites:
    – Block rotation with |rotate|
    – User check
    – Server-side device detection
    – Referer check
    – Debugging functions

    Is Ad-Inserter supposed to generate cookies, and is this going to break my caching?

    Thanks so much for any help you can provide!
    Adina

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Igor

    (@spacetime)

    No, cookies will not break caching. They are used only to save enabled debugging functons.

    Of course, while using debugging functions you should disable caching.

    Thanks, Igor! This is the cookie that my host said was being generated:

    $ curl -I (my site URL removed)
    HTTP/1.1 200 OK
    Server: openresty/1.11.2.1
    Date: Sun, 02 Oct 2016 18:56:53 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    Keep-Alive: timeout=30
    Link: <(my site URL removed)>; rel=”https://api.w.org/”
    Set-Cookie: AI_WP_DEBUGGING=0; expires=Sun, 02-Oct-2016 19:56:53 GMT; Max-Age=3600; path=/
    Set-Cookie: AI_WP_DEBUG_BLOCK=0; expires=Sun, 02-Oct-2016 19:56:53 GMT; Max-Age=3600; path=/
    Vary: Accept-Encoding, User-Agent
    X-User-Agent: standard
    X-Cache-Config: 0 1
    X-Cache-Status: BYPASS

    Does this look normal, and all is ok? I don’t have any debugging functions enabled that I know of.

    Plugin Author Igor

    (@spacetime)

    It looks normal 🙂

    Debugging functions are disabled and in next version in such case cookie will not be generated.

    Thanks for your help, I appreciate it. 🙂

    Hi Igor,

    I wanted to check and see when you’re planning on releasing the next version of this plugin with the cookies not being generated?

    Thanks so much for your help!
    Adina

    • This reply was modified 1 year, 2 months ago by  adinamichelle.
    Plugin Author Igor

    (@spacetime)

    Please try development version:
    https://downloads.wordpress.org/plugin/ad-inserter.zip

    Cookie is now created only when debugging is enabled.

    Thank you again! 🙂

    Hi Igor,

    Thanks for releasing the newest version! Is there a way to disable cookies entirely in this version of the plugin?

    Plugin Author Igor

    (@spacetime)

    The latest version does not use cookies unless you enable debugging functons. And when you enable debugging it uses cookie only for the logged in admin user.

    Hi Igor,

    I’ve spent a couple of time working on checking things to allow cache on pagely using your plugin in a client website.

    As you stated you’re removing the cookies when !is_admin(), this is correct, but pagely still detects the header cookies and disables caching on the website.

    The way to solve this would be to remove_action() the debugging functions from ‘wp’ when debug mode is off.

    I’ve managed to make this work creating a small plugin to remove your hook. But I think it would be good to have this in your code when debug is off.

    Thanks

    Plugin Author Igor

    (@spacetime)

    Thanks for suggestion.
    I’ll try to include this in the next release.

    Plugin Author Igor

    (@spacetime)

    Hi,

    Can you please be more specific – which hook causes issues with cookies?

    Ricardo Correia

    (@ricardocorreia)

    Hi igor, sure.
    Here’s the code of my simple plugin that solves the issue:

    remove_action( 'wp', 'ai_wp_hook' );
    
    function foundry_ai_wp_hook () {
      global $ai_wp_data, $ai_db_options_extract;
    
      if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("WP HOOK START");
      set_page_type ();
      set_user ();
    
      if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_ADMIN && ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0 && get_admin_toolbar_debugging ())
        add_action ('admin_bar_menu', 'ai_toolbar', 20);
    
      $url_debugging = get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0;
    
      if (!is_admin()) {
        if (isset ($_GET [AI_URL_DEBUG]) && $_GET [AI_URL_DEBUG] == 0) {
          unset ($_COOKIE ['AI_WP_DEBUGGING']);
          setcookie ('AI_WP_DEBUGGING', '', time() - (15 * 60), COOKIEPATH);
          unset ($_COOKIE ['AI_WP_DEBUG_BLOCK']);
          setcookie ('AI_WP_DEBUG_BLOCK', '', time() - (15 * 60), COOKIEPATH);
        } else {
            $ai_wp_data [AI_WP_DEBUGGING]   = isset ($_COOKIE ['AI_WP_DEBUGGING'])   ? $ai_wp_data [AI_WP_DEBUGGING] | ($_COOKIE ['AI_WP_DEBUGGING'] & ~AI_DEBUG_PROCESSING) : $ai_wp_data [AI_WP_DEBUGGING];
            $ai_wp_data [AI_WP_DEBUG_BLOCK] = isset ($_COOKIE ['AI_WP_DEBUG_BLOCK']) ? $_COOKIE ['AI_WP_DEBUG_BLOCK'] : 0;
    
            if (isset ($_GET [AI_URL_DEBUG_BLOCKS]))
              if ($_GET [AI_URL_DEBUG_BLOCKS] && $url_debugging) $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_BLOCKS; else $ai_wp_data [AI_WP_DEBUGGING] &= ~AI_DEBUG_BLOCKS;
    
            if (isset ($_GET [AI_URL_DEBUG_TAGS]))
              if ($_GET [AI_URL_DEBUG_TAGS] && $url_debugging) $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_TAGS; else $ai_wp_data [AI_WP_DEBUGGING] &= ~AI_DEBUG_TAGS;
    
            if (isset ($_GET [AI_URL_DEBUG_NO_INSERTION]))
              if ($_GET [AI_URL_DEBUG_NO_INSERTION] && $url_debugging) $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_NO_INSERTION; else $ai_wp_data [AI_WP_DEBUGGING] &= ~AI_DEBUG_NO_INSERTION;
    
            if (isset ($_GET [AI_URL_DEBUG_POSITIONS])) {
              if ($_GET [AI_URL_DEBUG_POSITIONS] !== '' && $url_debugging) $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_POSITIONS; else $ai_wp_data [AI_WP_DEBUGGING] &= ~AI_DEBUG_POSITIONS;
              if (is_numeric ($_GET [AI_URL_DEBUG_POSITIONS])) $ai_wp_data [AI_WP_DEBUG_BLOCK] = intval ($_GET [AI_URL_DEBUG_POSITIONS]);
              if ($ai_wp_data [AI_WP_DEBUG_BLOCK] < 0 || $ai_wp_data [AI_WP_DEBUG_BLOCK] > AD_INSERTER_BLOCKS) $ai_wp_data [AI_WP_DEBUG_BLOCK] = 0;
            }
    
            if ($ai_wp_data [AI_WP_DEBUGGING] != 0)
              setcookie ('AI_WP_DEBUGGING',   $ai_wp_data [AI_WP_DEBUGGING],   time() + AI_COOKIE_TIME, COOKIEPATH);
            if ($ai_wp_data [AI_WP_DEBUG_BLOCK] != 0)
              setcookie ('AI_WP_DEBUG_BLOCK', $ai_wp_data [AI_WP_DEBUG_BLOCK], time() + AI_COOKIE_TIME, COOKIEPATH);
          }
      }
    
      $debug_positions             = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0;
      $debug_tags_positions        = ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_TAGS)) != 0;
      $debug_tags_positions_blocks = ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_TAGS | AI_DEBUG_BLOCKS)) != 0;
    
      $plugin_priority = get_plugin_priority ();
      if (isset ($ai_db_options_extract [CONTENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [CONTENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_tags_positions)
        add_filter ('the_content',        'ai_content_hook', $plugin_priority);
    
      if (isset ($ai_db_options_extract [EXCERPT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [EXCERPT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_tags_positions_blocks)
        add_filter ('the_excerpt',        'ai_excerpt_hook', $plugin_priority);
    
      if (isset ($ai_db_options_extract [LOOP_START_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [LOOP_START_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_positions)
        add_action ('loop_start',         'ai_loop_start_hook');
    
      if (isset ($ai_db_options_extract [LOOP_END_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [LOOP_END_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_positions)
        add_action ('loop_end',           'ai_loop_end_hook');
    
      if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("WP HOOK END\n");
    };
    
    add_action( 'wp', 'foundry_ai_wp_hook' );
    
    Plugin Author Igor

    (@spacetime)

    Please check development version
    https://downloads.wordpress.org/plugin/ad-inserter.zip

    https://plugins.svn.wordpress.org/ad-inserter/trunk/ad-inserter.php

    If there is no cookie and debugging is off then the cookie is not created/deleted.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Plugin Generates Cookies, Breaks Caching?’ is closed to new replies.