diff --git a/automation/helpers.php b/automation/helpers.php index 382187a..5edbd79 100644 --- a/automation/helpers.php +++ b/automation/helpers.php @@ -138,14 +138,15 @@ function processAbuseDetection($pdo, $domain, $clid, $abuseType, $evidenceLink, } function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = 'create', $registrar_id = null, $currency = 'USD') { + $redis = new Redis(); + $redis->connect('127.0.0.1', 6379); + $cacheKey = "domain_price_{$domain_name}_{$tld_id}_{$date_add}_{$command}_{$registrar_id}_{$currency}"; // Try fetching from cache - if (function_exists('apcu_fetch')) { - $cached = apcu_fetch($cacheKey); - if ($cached !== false) { - return $cached; - } + $cached = $redis->get($cacheKey); + if ($cached !== false) { + return json_decode($cached, true); // Redis stores as string, so decode } $exchangeRates = getExchangeRates(); @@ -153,7 +154,7 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = $exchangeRate = $exchangeRates['rates'][$currency] ?? 1.0; // Check for premium pricing - $premiumPrice = apcu_fetch("premium_price_{$domain_name}_{$tld_id}") ?: fetchSingleValue( + $premiumPrice = $redis->get("premium_price_{$domain_name}_{$tld_id}") ?: fetchSingleValue( $pdo, 'SELECT c.category_price FROM premium_domain_pricing p @@ -166,13 +167,13 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = $money = convertMoney(new Money((int) ($premiumPrice * 100), new Currency($baseCurrency)), $exchangeRate, $currency); $result = ['type' => 'premium', 'price' => formatMoney($money)]; - apcu_store($cacheKey, $result, 1800); + $redis->setex($cacheKey, 1800, json_encode($result)); return $result; } // Check for active promotions $currentDate = date('Y-m-d'); - $promo = apcu_fetch("promo_{$tld_id}") ?: fetchSingleRow( + $promo = json_decode($redis->get("promo_{$tld_id}"), true) ?: fetchSingleRow( $pdo, "SELECT discount_percentage, discount_amount FROM promotion_pricing @@ -185,12 +186,12 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = ); if ($promo) { - apcu_store("promo_{$tld_id}", $promo, 3600); + $redis->setex("promo_{$tld_id}", 3600, json_encode($promo)); } // Get regular price from DB $priceColumn = "m" . (int) $date_add; - $regularPrice = apcu_fetch("regular_price_{$tld_id}_{$command}_{$registrar_id}") ?: fetchSingleValue( + $regularPrice = json_decode($redis->get("regular_price_{$tld_id}_{$command}_{$registrar_id}"), true) ?: fetchSingleValue( $pdo, "SELECT $priceColumn FROM domain_price @@ -201,7 +202,7 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = ); if (!is_null($regularPrice) && $regularPrice !== false) { - apcu_store("regular_price_{$tld_id}_{$command}_{$registrar_id}", $regularPrice, 1800); + $redis->setex("regular_price_{$tld_id}_{$command}_{$registrar_id}", 1800, json_encode($regularPrice)); $finalPrice = $regularPrice * 100; // Convert DB float to cents if ($promo) { @@ -219,7 +220,7 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = $money = convertMoney(new Money($finalPrice, new Currency($baseCurrency)), $exchangeRate, $currency); $result = ['type' => $type, 'price' => formatMoney($money)]; - apcu_store($cacheKey, $result, 1800); + $redis->setex($cacheKey, 1800, json_encode($result)); return $result; } @@ -230,13 +231,14 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = * Load exchange rates from JSON file with APCu caching. */ function getExchangeRates() { + $redis = new Redis(); + $redis->connect('127.0.0.1', 6379); + $cacheKey = 'exchange_rates'; - if (function_exists('apcu_fetch')) { - $cached = apcu_fetch($cacheKey); - if ($cached !== false) { - return $cached; - } + $cached = $redis->get($cacheKey); + if ($cached !== false) { + return json_decode($cached, true); } $filePath = "/var/www/cp/resources/exchange_rates.json"; @@ -249,9 +251,7 @@ function getExchangeRates() { ]; if (!file_exists($filePath) || !is_readable($filePath)) { - if (function_exists('apcu_store')) { - apcu_store($cacheKey, $defaultRates, 3600); - } + $redis->setex($cacheKey, 3600, json_encode($defaultRates)); // Cache for 1 hour return $defaultRates; } @@ -259,9 +259,7 @@ function getExchangeRates() { $data = json_decode($json, true); if (!isset($data['base_currency'], $data['rates']) || !is_array($data['rates'])) { - if (function_exists('apcu_store')) { - apcu_store($cacheKey, $defaultRates, 3600); - } + $redis->setex($cacheKey, 3600, json_encode($defaultRates)); // Cache for 1 hour return $defaultRates; } @@ -277,9 +275,7 @@ function getExchangeRates() { } } - if (function_exists('apcu_store')) { - apcu_store($cacheKey, $data, 3600); - } + $redis->setex($cacheKey, 3600, json_encode($data)); // Cache for 1 hour return $data; } diff --git a/cp/app/Controllers/DapiController.php b/cp/app/Controllers/DapiController.php index bd34e4b..cafe752 100644 --- a/cp/app/Controllers/DapiController.php +++ b/cp/app/Controllers/DapiController.php @@ -768,9 +768,12 @@ class DapiController extends Controller $registrar_id = !empty($params['registrar_id']) ? $params['registrar_id'] : ($_SESSION['auth_registrar_id'] ?? null); $parts = extractDomainAndTLD($domain_name); - $domain_extension = $parts['tld']; + $domain_extension = $parts['tld'] ?? null; - $tld_id = $db->selectValue('SELECT id FROM domain_tld WHERE tld = ?', [ '.'.$domain_extension ]); + $tld_id = null; + if ($domain_extension !== null) { + $tld_id = $db->selectValue('SELECT id FROM domain_tld WHERE tld = ?', ['.' . $domain_extension]); + } $result = getDomainPrice($db, $domain_name, $tld_id, $date_add, $command, $registrar_id, $currency); diff --git a/cp/bootstrap/helper.php b/cp/bootstrap/helper.php index caa52c7..6bd35c6 100644 --- a/cp/bootstrap/helper.php +++ b/cp/bootstrap/helper.php @@ -442,14 +442,15 @@ function extractDomainAndTLD($urlString) { } function getDomainPrice($db, $domain_name, $tld_id, $date_add = 12, $command = 'create', $registrar_id = null, $currency = 'USD') { + $redis = new Redis(); + $redis->connect('127.0.0.1', 6379); + $cacheKey = "domain_price_{$domain_name}_{$tld_id}_{$date_add}_{$command}_{$registrar_id}_{$currency}"; // Try fetching from cache - if (function_exists('apcu_fetch')) { - $cached = apcu_fetch($cacheKey); - if ($cached !== false) { - return $cached; - } + $cached = $redis->get($cacheKey); + if ($cached !== false) { + return json_decode($cached, true); // Redis stores as string, so decode } $exchangeRates = getExchangeRates(); @@ -457,7 +458,7 @@ function getDomainPrice($db, $domain_name, $tld_id, $date_add = 12, $command = ' $exchangeRate = $exchangeRates['rates'][$currency] ?? 1.0; // Check for premium pricing - $premiumPrice = apcu_fetch("premium_price_{$domain_name}_{$tld_id}") ?: $db->selectValue( + $premiumPrice = $redis->get("premium_price_{$domain_name}_{$tld_id}") ?: $db->selectValue( 'SELECT c.category_price FROM premium_domain_pricing p JOIN premium_domain_categories c ON p.category_id = c.category_id @@ -469,13 +470,13 @@ function getDomainPrice($db, $domain_name, $tld_id, $date_add = 12, $command = ' $money = convertMoney(new Money((int) ($premiumPrice * 100), new Currency($baseCurrency)), $exchangeRate, $currency); $result = ['type' => 'premium', 'price' => formatMoney($money)]; - apcu_store($cacheKey, $result, 1800); + $redis->setex($cacheKey, 1800, json_encode($result)); return $result; } // Check for active promotions $currentDate = date('Y-m-d'); - $promo = apcu_fetch("promo_{$tld_id}") ?: $db->selectRow( + $promo = json_decode($redis->get("promo_{$tld_id}"), true) ?: $db->selectRow( "SELECT discount_percentage, discount_amount FROM promotion_pricing WHERE tld_id = ? @@ -487,12 +488,12 @@ function getDomainPrice($db, $domain_name, $tld_id, $date_add = 12, $command = ' ); if ($promo) { - apcu_store("promo_{$tld_id}", $promo, 3600); + $redis->setex("promo_{$tld_id}", 3600, json_encode($promo)); } // Get regular price from DB $priceColumn = "m" . (int) $date_add; - $regularPrice = apcu_fetch("regular_price_{$tld_id}_{$command}_{$registrar_id}") ?: $db->selectValue( + $regularPrice = json_decode($redis->get("regular_price_{$tld_id}_{$command}_{$registrar_id}"), true) ?: $db->selectValue( "SELECT $priceColumn FROM domain_price WHERE tldid = ? AND command = ? @@ -502,7 +503,7 @@ function getDomainPrice($db, $domain_name, $tld_id, $date_add = 12, $command = ' ); if (!is_null($regularPrice) && $regularPrice !== false) { - apcu_store("regular_price_{$tld_id}_{$command}_{$registrar_id}", $regularPrice, 1800); + $redis->setex("regular_price_{$tld_id}_{$command}_{$registrar_id}", 1800, json_encode($regularPrice)); $finalPrice = $regularPrice * 100; // Convert DB float to cents if ($promo) { @@ -520,7 +521,7 @@ function getDomainPrice($db, $domain_name, $tld_id, $date_add = 12, $command = ' $money = convertMoney(new Money($finalPrice, new Currency($baseCurrency)), $exchangeRate, $currency); $result = ['type' => $type, 'price' => formatMoney($money)]; - apcu_store($cacheKey, $result, 1800); + $redis->setex($cacheKey, 1800, json_encode($result)); return $result; } @@ -528,14 +529,15 @@ function getDomainPrice($db, $domain_name, $tld_id, $date_add = 12, $command = ' } function getDomainRestorePrice($db, $tld_id, $registrar_id = null, $currency = 'USD') { + $redis = new Redis(); + $redis->connect('127.0.0.1', 6379); + $cacheKey = "domain_restore_price_{$tld_id}_{$registrar_id}_{$currency}"; // Try fetching from cache - if (function_exists('apcu_fetch')) { - $cached = apcu_fetch($cacheKey); - if ($cached !== false) { - return $cached; - } + $cached = $redis->get($cacheKey); + if ($cached !== false) { + return json_decode($cached, true); } // Fetch exchange rates @@ -564,7 +566,7 @@ function getDomainRestorePrice($db, $tld_id, $registrar_id = null, $currency = ' // Format and cache the result $formattedPrice = formatMoney($money); - apcu_store($cacheKey, $formattedPrice, 1800); // Cache for 30 minutes + $redis->setex($cacheKey, 1800, json_encode($formattedPrice)); return $formattedPrice; } @@ -573,13 +575,14 @@ function getDomainRestorePrice($db, $tld_id, $registrar_id = null, $currency = ' * Load exchange rates from JSON file with APCu caching. */ function getExchangeRates() { + $redis = new Redis(); + $redis->connect('127.0.0.1', 6379); + $cacheKey = 'exchange_rates'; - if (function_exists('apcu_fetch')) { - $cached = apcu_fetch($cacheKey); - if ($cached !== false) { - return $cached; - } + $cached = $redis->get($cacheKey); + if ($cached !== false) { + return json_decode($cached, true); } $filePath = "/var/www/cp/resources/exchange_rates.json"; @@ -592,9 +595,7 @@ function getExchangeRates() { ]; if (!file_exists($filePath) || !is_readable($filePath)) { - if (function_exists('apcu_store')) { - apcu_store($cacheKey, $defaultRates, 3600); - } + $redis->setex($cacheKey, 3600, json_encode($defaultRates)); // Cache for 1 hour return $defaultRates; } @@ -602,9 +603,7 @@ function getExchangeRates() { $data = json_decode($json, true); if (!isset($data['base_currency'], $data['rates']) || !is_array($data['rates'])) { - if (function_exists('apcu_store')) { - apcu_store($cacheKey, $defaultRates, 3600); - } + $redis->setex($cacheKey, 3600, json_encode($defaultRates)); // Cache for 1 hour return $defaultRates; } @@ -620,9 +619,7 @@ function getExchangeRates() { } } - if (function_exists('apcu_store')) { - apcu_store($cacheKey, $data, 3600); - } + $redis->setex($cacheKey, 3600, json_encode($data)); // Cache for 1 hour return $data; } diff --git a/docs/install.sh b/docs/install.sh index c6fdf4d..0dfaa74 100644 --- a/docs/install.sh +++ b/docs/install.sh @@ -117,7 +117,7 @@ if [[ ("$OS" == "Ubuntu" && "$VER" == "22.04") || ("$OS" == "Ubuntu" && "$VER" = apt update -y echo "Installing PHP and required extensions..." - apt install -y ${PHP_VERSION} ${PHP_VERSION}-apcu ${PHP_VERSION}-bcmath ${PHP_VERSION}-cli ${PHP_VERSION}-common ${PHP_VERSION}-curl ${PHP_VERSION}-ds ${PHP_VERSION}-fpm ${PHP_VERSION}-gd ${PHP_VERSION}-gmp ${PHP_VERSION}-gnupg ${PHP_VERSION}-igbinary ${PHP_VERSION}-imap ${PHP_VERSION}-intl ${PHP_VERSION}-mbstring ${PHP_VERSION}-opcache ${PHP_VERSION}-readline ${PHP_VERSION}-redis ${PHP_VERSION}-soap ${PHP_VERSION}-swoole ${PHP_VERSION}-uuid ${PHP_VERSION}-xml + apt install -y ${PHP_VERSION} ${PHP_VERSION}-bcmath ${PHP_VERSION}-cli ${PHP_VERSION}-common ${PHP_VERSION}-curl ${PHP_VERSION}-ds ${PHP_VERSION}-fpm ${PHP_VERSION}-gd ${PHP_VERSION}-gmp ${PHP_VERSION}-gnupg ${PHP_VERSION}-igbinary ${PHP_VERSION}-imap ${PHP_VERSION}-intl ${PHP_VERSION}-mbstring ${PHP_VERSION}-opcache ${PHP_VERSION}-readline ${PHP_VERSION}-redis ${PHP_VERSION}-soap ${PHP_VERSION}-swoole ${PHP_VERSION}-uuid ${PHP_VERSION}-xml # Set timezone to UTC if it's not already currentTimezone=$(timedatectl status | grep "Time zone" | awk '{print $3}') diff --git a/docs/update1015.sh b/docs/update1015.sh index 8a27f01..9184903 100644 --- a/docs/update1015.sh +++ b/docs/update1015.sh @@ -64,7 +64,7 @@ systemctl stop msg_worker echo "Clearing cache..." php /var/www/cp/bin/clear_cache.php -apt install -y php8.3-apcu php8.3-bcmath +apt install -y php8.3-bcmath # Clone the new version of the repository echo "Cloning v1.0.15 from the repository..." diff --git a/epp/src/helpers.php b/epp/src/helpers.php index 73d88cb..46f1e6e 100644 --- a/epp/src/helpers.php +++ b/epp/src/helpers.php @@ -608,14 +608,15 @@ function updatePermittedIPs($pool, $permittedIPsTable) { } function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = 'create', $registrar_id = null, $currency = 'USD') { + $redis = new Redis(); + $redis->connect('127.0.0.1', 6379); + $cacheKey = "domain_price_{$domain_name}_{$tld_id}_{$date_add}_{$command}_{$registrar_id}_{$currency}"; // Try fetching from cache - if (function_exists('apcu_fetch')) { - $cached = apcu_fetch($cacheKey); - if ($cached !== false) { - return $cached; - } + $cached = $redis->get($cacheKey); + if ($cached !== false) { + return json_decode($cached, true); // Redis stores as string, so decode } $exchangeRates = getExchangeRates(); @@ -623,7 +624,7 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = $exchangeRate = $exchangeRates['rates'][$currency] ?? 1.0; // Check for premium pricing - $premiumPrice = apcu_fetch("premium_price_{$domain_name}_{$tld_id}") ?: fetchSingleValue( + $premiumPrice = $redis->get("premium_price_{$domain_name}_{$tld_id}") ?: fetchSingleValue( $pdo, 'SELECT c.category_price FROM premium_domain_pricing p @@ -636,13 +637,13 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = $money = convertMoney(new Money((int) ($premiumPrice * 100), new Currency($baseCurrency)), $exchangeRate, $currency); $result = ['type' => 'premium', 'price' => formatMoney($money)]; - apcu_store($cacheKey, $result, 1800); + $redis->setex($cacheKey, 1800, json_encode($result)); return $result; } // Check for active promotions $currentDate = date('Y-m-d'); - $promo = apcu_fetch("promo_{$tld_id}") ?: fetchSingleRow( + $promo = json_decode($redis->get("promo_{$tld_id}"), true) ?: fetchSingleRow( $pdo, "SELECT discount_percentage, discount_amount FROM promotion_pricing @@ -655,12 +656,12 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = ); if ($promo) { - apcu_store("promo_{$tld_id}", $promo, 3600); + $redis->setex("promo_{$tld_id}", 3600, json_encode($promo)); } // Get regular price from DB $priceColumn = "m" . (int) $date_add; - $regularPrice = apcu_fetch("regular_price_{$tld_id}_{$command}_{$registrar_id}") ?: fetchSingleValue( + $regularPrice = json_decode($redis->get("regular_price_{$tld_id}_{$command}_{$registrar_id}"), true) ?: fetchSingleValue( $pdo, "SELECT $priceColumn FROM domain_price @@ -671,7 +672,7 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = ); if (!is_null($regularPrice) && $regularPrice !== false) { - apcu_store("regular_price_{$tld_id}_{$command}_{$registrar_id}", $regularPrice, 1800); + $redis->setex("regular_price_{$tld_id}_{$command}_{$registrar_id}", 1800, json_encode($regularPrice)); $finalPrice = $regularPrice * 100; // Convert DB float to cents if ($promo) { @@ -689,7 +690,7 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = $money = convertMoney(new Money($finalPrice, new Currency($baseCurrency)), $exchangeRate, $currency); $result = ['type' => $type, 'price' => formatMoney($money)]; - apcu_store($cacheKey, $result, 1800); + $redis->setex($cacheKey, 1800, json_encode($result)); return $result; } @@ -697,14 +698,15 @@ function getDomainPrice($pdo, $domain_name, $tld_id, $date_add = 12, $command = } function getDomainRestorePrice($pdo, $tld_id, $registrar_id = null, $currency = 'USD') { + $redis = new Redis(); + $redis->connect('127.0.0.1', 6379); + $cacheKey = "domain_restore_price_{$tld_id}_{$registrar_id}_{$currency}"; // Try fetching from cache - if (function_exists('apcu_fetch')) { - $cached = apcu_fetch($cacheKey); - if ($cached !== false) { - return $cached; - } + $cached = $redis->get($cacheKey); + if ($cached !== false) { + return json_decode($cached, true); } // Fetch exchange rates @@ -734,7 +736,7 @@ function getDomainRestorePrice($pdo, $tld_id, $registrar_id = null, $currency = // Format and cache the result $formattedPrice = formatMoney($money); - apcu_store($cacheKey, $formattedPrice, 1800); // Cache for 30 minutes + $redis->setex($cacheKey, 1800, json_encode($formattedPrice)); return $formattedPrice; } @@ -743,13 +745,14 @@ function getDomainRestorePrice($pdo, $tld_id, $registrar_id = null, $currency = * Load exchange rates from JSON file with APCu caching. */ function getExchangeRates() { + $redis = new Redis(); + $redis->connect('127.0.0.1', 6379); + $cacheKey = 'exchange_rates'; - if (function_exists('apcu_fetch')) { - $cached = apcu_fetch($cacheKey); - if ($cached !== false) { - return $cached; - } + $cached = $redis->get($cacheKey); + if ($cached !== false) { + return json_decode($cached, true); } $filePath = "/var/www/cp/resources/exchange_rates.json"; @@ -762,9 +765,7 @@ function getExchangeRates() { ]; if (!file_exists($filePath) || !is_readable($filePath)) { - if (function_exists('apcu_store')) { - apcu_store($cacheKey, $defaultRates, 3600); - } + $redis->setex($cacheKey, 3600, json_encode($defaultRates)); // Cache for 1 hour return $defaultRates; } @@ -772,9 +773,7 @@ function getExchangeRates() { $data = json_decode($json, true); if (!isset($data['base_currency'], $data['rates']) || !is_array($data['rates'])) { - if (function_exists('apcu_store')) { - apcu_store($cacheKey, $defaultRates, 3600); - } + $redis->setex($cacheKey, 3600, json_encode($defaultRates)); // Cache for 1 hour return $defaultRates; } @@ -790,9 +789,7 @@ function getExchangeRates() { } } - if (function_exists('apcu_store')) { - apcu_store($cacheKey, $data, 3600); - } + $redis->setex($cacheKey, 3600, json_encode($data)); // Cache for 1 hour return $data; }