public static function _read_unbounce_domain_info($options_getter, $options_setter, $fetch_proxyable_url_set, $domain, $expire_now = false) { $proxyable_url_set = null; $cache_max_time_default = 10; $ps_domain = $options_getter(UBConfig::UB_PAGE_SERVER_DOMAIN_KEY); $domains_info = $options_getter(UBConfig::UB_ROUTES_CACHE_KEY); $domain_info = UBUtil::array_fetch($domains_info, $domain, array()); $proxyable_url_set = UBUtil::array_fetch($domain_info, 'proxyable_url_set'); $proxyable_url_set_fetched_at = UBUtil::array_fetch($domain_info, 'proxyable_url_set_fetched_at'); $proxyable_url_set_cache_timeout = UBUtil::array_fetch($domain_info, 'proxyable_url_set_cache_timeout'); $proxyable_url_set_etag = UBUtil::array_fetch($domain_info, 'proxyable_url_set_etag'); $cache_max_time = is_null($proxyable_url_set_cache_timeout) ? $cache_max_time_default : $proxyable_url_set_cache_timeout; $current_time = time(); if ($expire_now || is_null($proxyable_url_set) || $current_time - $proxyable_url_set_fetched_at > $cache_max_time) { try { $can_fetch = UBUtil::get_lock(); UBLogger::debug('Locking: ' . $can_fetch); if ($can_fetch) { $result_array = call_user_func($fetch_proxyable_url_set, $domain, $proxyable_url_set_etag, $ps_domain); list($routes_status, $etag, $max_age, $proxyable_url_set_new) = $result_array; if ($routes_status['status'] == 'NEW') { $domain_info['proxyable_url_set'] = $proxyable_url_set_new; $domain_info['proxyable_url_set_etag'] = $etag; $domain_info['proxyable_url_set_cache_timeout'] = $max_age; } elseif ($routes_status['status'] == 'SAME') { // Just extend the cache $domain_info['proxyable_url_set_cache_timeout'] = $max_age; } elseif ($routes_status['status'] == 'NONE') { $domain_info['proxyable_url_set'] = array(); $domain_info['proxyable_url_set_etag'] = null; } elseif ($routes_status['status'] == 'FAILURE') { UBLogger::warning('Route fetching failed'); } else { UBLogger::warning("Unknown response from route fetcher: '{$routes_status}'"); } // Creation of domain_info entry $domain_info['proxyable_url_set_fetched_at'] = $current_time; $domain_info['last_status'] = $routes_status['status']; if ($routes_status['status'] == 'FAILURE') { $domain_info['failure_message'] = $routes_status['failure_message']; } $domains_info[$domain] = $domain_info; // set autoload to false so that options are always loaded from DB $options_setter(UBConfig::UB_ROUTES_CACHE_KEY, $domains_info, false); } } catch (Exception $e) { UBLogger::warning('Could not update sitemap: ' . $e); } $release_result = UBUtil::release_lock(); UBLogger::debug('Unlocking: ' . $release_result); } return UBUtil::array_select_by_key($domain_info, array('proxyable_url_set', 'proxyable_url_set_fetched_at', 'failure_message', 'last_status')); }
define('DONOTCACHEPAGE', true); } if (!defined('DONOTCDN')) { define('DONOTCDN', true); } if (!defined('DONOTCACHEDB')) { define('DONOTCACHEDB', true); } if (!defined('DONOTMINIFY')) { define('DONOTMINIFY', true); } if (!defined('DONOTCACHEOBJECT')) { define('DONOTCACHEOBJECT', true); } UBLogger::debug("perform ''" . $url_purpose . "'' on received URL " . $current_url); $cookies_to_forward = UBUtil::array_select_by_key($_COOKIE, array('ubvs', 'ubpv', 'ubvt')); $cookie_string = UBHTTP::cookie_string_from_array($cookies_to_forward); $req_headers = $referer == null ? array('Host: ' . $domain) : array('Referer: ' . $referer, 'Host: ' . $domain); // Make sure we don't get cached by Wordpress hosts like WPEngine header('Cache-Control: max-age=0; private'); list($success, $message) = UBHTTP::stream_request($http_method, $raw_url, $cookie_string, $req_headers, $user_agent); if ($success === false) { update_option(UBConfig::UB_PROXY_ERROR_MESSAGE_KEY, $message); } $end = microtime(true); $time_taken = ($end - $start) * 1000; UBLogger::debug_var('time_taken', $time_taken); UBLogger::debug("proxying for {$current_url} done successfuly -- took {$time_taken} ms"); exit(0); } }, UBConfig::int_min());