private static function checkHoneyPotCached($config, $remote_ip) { $params = array(); $params["remote_ip"] = $remote_ip; $boolean_result = \util\CacheSql::get_cached_read_result_apc_type_convert($config, $params, self::$class_name); return $boolean_result; }
public function getPerTimeCached($config, $where_params = null, $time_to_live = 900, $refresh = false, $is_admin = FALSE) { $cached_data = \util\CacheSql::get_cached_read_result_apc($config, $where_params, $this->table . '_M'); if ($cached_data !== null && !$refresh) { if ($cached_data == self::$empty_array_value) { return array(); } else { return $cached_data; } } else { $data = $this->getPerTime($where_params, $is_admin); \util\CacheSql::put_cached_read_result_apc($config, $where_params, $this->table . '_M', $data, $time_to_live); return $data; } }
public function incrementBuySideHourlyImpressionsByTLDCached($config, $banner_id, $tld) { $params = array(); $params["AdCampaignBannerID"] = $banner_id; $params["PublisherTLD"] = $tld; $class_dir_name = 'BuySideHourlyImpressionsByTLD'; $cached_key_exists = \util\CacheSql::does_cached_write_exist_apc($config, $params, $class_dir_name); if ($cached_key_exists) { // increment bucket \util\CachedStatsWrites::increment_cached_write_result_int_apc($config, $params, $class_dir_name, 1); } else { // get value sum from apc $current = \util\CacheSql::get_cached_read_result_apc($config, $params, $class_dir_name); if ($current != null) { $bucket_value = $current["value"]; // write out value $this->incrementBuySideHourlyImpressionsByTLD($banner_id, $tld, $bucket_value); } // delete existing key - reset bucket \util\CacheSql::delete_cached_write_apc($config, $params, $class_dir_name); // increment bucket \util\CachedStatsWrites::increment_cached_write_result_int_apc($config, $params, $class_dir_name, 1); } }
public static function increment_cached_write_result_int_apc($config, $params, $class_name, $value, $ttl = 60) { $current = \util\CacheSql::get_cached_read_result_apc($config, $params, $class_name); if ($current !== null) { $existing_value = intval($current["value"]); $value += $existing_value; } // cache up to 1 hour, the write the the db should occur before that. \util\CacheSql::put_cached_read_result_apc($config, $params, $class_name, array("value" => intval($value)), 3600); $timer_name = 'write_timer'; $write_timer = \util\CacheSql::get_cached_read_result_apc($config, $params, $class_name . $timer_name); if ($write_timer == null) { /* * 60 second write timer, when the apc cache value is gone the * contents are written the DB and the apc value is cleared */ \util\CacheSql::put_cached_read_result_apc($config, $params, $class_name . $timer_name, array($timer_name => true), 60); } }
public function incrementBuySideHourlyImpressionsByTLDCached($config, $banner_id, $tld) { $params = array(); $params["InsertionOrderLineItemID"] = $banner_id; $params["PublisherTLD"] = $tld; $class_dir_name = 'BuySideHourlyImpressionsByTLD'; $cached_key_exists = \util\CacheSql::does_cached_write_exist_apc($config, $params, $class_dir_name); if ($cached_key_exists) { // increment bucket \util\CachedStatsWrites::increment_cached_write_result_int_apc($config, $params, $class_dir_name, 1); } else { /* * DO THIS BEFORE APC RESET OPERATIONS TO AVOID THREAD-LIKE DUPLICATION DUE TO THE LACK OF * A SYNCHRONIZED KEYWORD IN PHP */ // SYNCHRONIZED BLOCK START \util\CacheSql::create_reset_write_lock($config, $params, $class_dir_name); // get value sum from apc $current = \util\CacheSql::get_cached_read_result_apc_type_convert($config, $params, $class_dir_name); // delete existing key - reset bucket \util\CacheSql::delete_cached_write_apc($config, $params, $class_dir_name); // increment bucket \util\CachedStatsWrites::increment_cached_write_result_int_apc($config, $params, $class_dir_name, 1); // SYNCHRONIZED BLOCK END \util\CacheSql::reset_write_unlock($config, $params, $class_dir_name); if ($current != null) { $bucket_value = $current["value"]; // write out value $this->incrementBuySideHourlyImpressionsByTLD($banner_id, $tld, $bucket_value); } } }
public function incrementPrivateExchangeRtbChannelDailyStatsCached($config, $method_params) { $publisher_website_id = $method_params["publisher_website_id"] = $method_params["rtb_channel_site_id"]; $rtb_channel_site_name = $method_params["rtb_channel_site_name"]; $impressions_offered_counter = $method_params["impressions_offered_counter"]; $auction_bids_counter = $method_params["auction_bids_counter"]; $spend_offered_in_bids = $method_params["spend_offered_in_bids"]; $floor_price_if_any = $method_params["floor_price_if_any"]; $params = array(); $class_dir_name = 'PrivateExchangeRtbChannelDailyStats'; $cached_key_exists = \util\CacheSql::does_cached_write_exist_apc($config, $params, $class_dir_name); if ($cached_key_exists) { // increment bucket \util\CachedStatsWrites::increment_cached_write_result_private_exchange_channel_stats($config, $params, $class_dir_name, $method_params); } else { /* * DO THIS BEFORE APC RESET OPERATIONS TO AVOID THREAD-LIKE DUPLICATION DUE TO THE LACK OF * A SYNCHRONIZED KEYWORD IN PHP */ // SYNCHRONIZED BLOCK START \util\CacheSql::create_reset_write_lock($config, $params, $class_dir_name); // get value sum from apc $current = \util\CacheSql::get_cached_read_result_apc_type_convert($config, $params, $class_dir_name); // delete existing key - reset bucket \util\CacheSql::delete_cached_write_apc($config, $params, $class_dir_name); // increment bucket \util\CachedStatsWrites::increment_cached_write_result_private_exchange_channel_stats($config, $params, $class_dir_name, $method_params); // SYNCHRONIZED BLOCK END \util\CacheSql::reset_write_unlock($config, $params, $class_dir_name); if ($current != null) { // write out values $this->incrementPrivateExchangeRtbChannelDailyStats($config, $current); } } }
private static function checkScoreCached($config, $page_to_check) { $params = array(); $params["PageURL"] = $page_to_check; $json_result = \util\CacheSql::get_cached_read_result_apc($config, $params, self::$class_name); return $json_result; }
private function updateTorIpBlockList() { if ($this->config['settings']['rtb']['tor_protected'] !== true) { return false; } $lines = file(self::$tor_file_source_location); if (count($lines) < 100) { // bad request return false; } $apc_cached_tor_ip_list = array(); if (is_writable($this->config['settings']['rtb']['tor_file_save_location'])) { try { $fh = fopen($this->config['settings']['rtb']['tor_file_save_location'], "w"); /* * write it in nginx conf.d file include format */ foreach ($lines as $line) { fwrite($fh, "deny " . trim($line) . ";\n"); } fclose($fh); } catch (Exception $e) { echo "Tor Save File Location is not writable, Exception: " . $e->getMessage(); } } foreach ($lines as $line) { $apc_cached_tor_ip_list[trim($line)] = 1; } $params = array(); // 2 hour cache \util\CacheSql::put_cached_read_result_apc($this->config, $params, "Maintenance", $apc_cached_tor_ip_list, 7200); return true; }
protected static function increment_frequency_impressions_counter($config, $params, $class_name, $increment_amount = 1) { $current = \util\CacheSql::get_cached_read_result_apc_type_convert($config, $params, $class_name); if ($current !== null) { $existing_impressions_counter = intval($current["ImpressionsCounter"]); $existing_impressions_counter += $increment_amount; } else { $existing_impressions_counter = $increment_amount; } // cache up to 1 hour, the write the the db should occur before that. \util\CacheSql::put_cached_read_result_apc($config, $params, $class_name, array("ImpressionsCounter" => $existing_impressions_counter), 3600); $timer_name = 'write_timer'; $write_timer = \util\CacheSql::get_cached_read_result_apc($config, $params, $class_name . $timer_name); if ($write_timer == null) { /* * 60 second write timer, when the apc cache value is gone the * contents are written the DB and the apc value is cleared */ \util\CacheSql::put_cached_read_result_apc($config, $params, $class_name . $timer_name, array($timer_name => true), 60); } }