Файл: system/functions/panel/speed_site.php
Строк: 132
<?php
/*
-------------------------------
Функция проверки скорости сайта
-------------------------------
*/
FUNCTION SPEED_SITE($url) {
$time_speed = MICROTIME();
$time_speed = EXPLODE(' ', $time_speed);
$time_speed = $time_speed[1] + $time_speed[0];
$start = $time_speed;
// Проверка корректности URL
IF (FILTER_VAR($url, FILTER_VALIDATE_URL)){
$surl = $url;
// Инициализация cURL
$curlInit = CURL_INIT($surl);
// Установка параметров запроса
CURL_SETOPT($curlInit, CURLOPT_CONNECTTIMEOUT, 10);
CURL_SETOPT($curlInit, CURLOPT_HEADER, TRUE);
CURL_SETOPT($curlInit, CURLOPT_NOBODY, TRUE);
CURL_SETOPT($curlInit, CURLOPT_RETURNTRANSFER, TRUE);
// Получение ответа
$response = CURL_EXEC($curlInit);
// закрываем CURL
CURL_CLOSE($curlInit);
$time_speed = MICROTIME();
$time_speed = EXPLODE(' ', $time_speed);
$time_speed = $time_speed[1] + $time_speed[0];
$finish = $time_speed;
$total_time = ROUND(($finish - $start), 2);
//Получаем скорость загрузки страницы
$speed = $total_time;
RETURN $speed;
}ELSE{
RETURN LG('Ошибка');
}
}
/*
------------------------
Функция склонения баллов
------------------------
*/
$sb1 = 'балл';
$sb2 = 'балла';
$sb3 = 'баллов';
FUNCTION SPEED_BALLS_OPTIMIZE($num){
GLOBAL $sb1, $sb2, $sb3;
$num = ABS($num) % 100; // берем число по модулю и сбрасываем сотни (делим на 100, а остаток присваиваем переменной $num)
$num_x = $num % 10; // сбрасываем десятки и записываем в новую переменную
IF ($num > 10 && $num < 20){
RETURN $sb3;
}ELSEIF ($num_x > 1 && $num_x < 5){
RETURN $sb2;
}ELSEIF ($num_x == 1){
RETURN $sb1;
RETURN $sb3;
}ELSE{
RETURN $sb3;
}
}
/*
---------------------------------------
Функция оценки скорости сайта по баллам
От 0 до 3000
---------------------------------------
*/
FUNCTION SPEED_BALLS($num){
IF ($num == "0.00"){
RETURN 3000;
}ELSEIF ($num >= "0.01" && $num <= "0.03"){
RETURN 3000;
}ELSEIF ($num >= "0.04" && $num <= "0.06"){
RETURN 2975;
}ELSEIF ($num >= "0.07" && $num <= "0.09"){
RETURN 2950;
}ELSEIF ($num >= "0.10" && $num <= "0.12"){
RETURN 2825;
}ELSEIF ($num >= "0.13" && $num <= "0.15"){
RETURN 2800;
}ELSEIF ($num >= "0.16" && $num <= "0.18"){
RETURN 2775;
}ELSEIF ($num >= "0.19" && $num <= "0.21"){
RETURN 2750;
}ELSEIF ($num >= "0.22" && $num <= "0.24"){
RETURN 2725;
}ELSEIF ($num >= "0.25" && $num <= "0.27"){
RETURN 2700;
}ELSEIF ($num >= "0.28" && $num <= "0.30"){
RETURN 2675;
}ELSEIF ($num >= "0.31" && $num <= "0.33"){
RETURN 2650;
}ELSEIF ($num >= "0.34" && $num <= "0.36"){
RETURN 2625;
}ELSEIF ($num >= "0.37" && $num <= "0.39"){
RETURN 2600;
}ELSEIF ($num >= "0.40" && $num <= "0.42"){
RETURN 2575;
}ELSEIF ($num >= "0.43" && $num <= "0.45"){
RETURN 2550;
}ELSEIF ($num >= "0.46" && $num <= "0.49"){
RETURN 2525;
}ELSEIF ($num >= "0.50" && $num <= "0.52"){
RETURN 2500;
}ELSEIF ($num >= "0.53" && $num <= "0.55"){
RETURN 2475;
}ELSEIF ($num >= "0.56" && $num <= "0.58"){
RETURN 2450;
}ELSEIF ($num >= "0.59" && $num <= "1.01"){
RETURN 2425;
}ELSEIF ($num >= "1.02" && $num <= "1.04"){
RETURN 2400;
}ELSEIF ($num >= "1.05" && $num <= "1.07"){
RETURN 2375;
}ELSEIF ($num >= "1.08" && $num <= "1.10"){
RETURN 2350;
}ELSEIF ($num >= "1.11" && $num <= "1.13"){
RETURN 2325;
}ELSEIF ($num >= "1.14" && $num <= "1.16"){
RETURN 2300;
}ELSEIF ($num >= "1.17" && $num <= "1.19"){
RETURN 2200;
}ELSEIF ($num >= "1.20" && $num <= "1.23"){
RETURN 2100;
}ELSEIF ($num >= "1.24" && $num <= "1.26"){
RETURN 2000;
}ELSEIF ($num >= "1.27" && $num <= "1.29"){
RETURN 1900;
}ELSEIF ($num >= "1.30" && $num <= "1.32"){
RETURN 1800;
}ELSEIF ($num >= "1.33" && $num <= "1.35"){
RETURN 1700;
}ELSEIF ($num >= "1.36" && $num <= "1.46"){
RETURN 1600;
}ELSEIF ($num >= "1.47" && $num <= "1.57"){
RETURN 1500;
}ELSEIF ($num >= "1.58" && $num <= "2.08"){
RETURN 1400;
}ELSEIF ($num >= "2.09" && $num <= "2.19"){
RETURN 1300;
}ELSEIF ($num >= "2.20" && $num <= "2.30"){
RETURN 1200;
}ELSEIF ($num >= "2.31" && $num <= "2.41"){
RETURN 1100;
}ELSEIF ($num >= "2.42" && $num <= "2.52"){
RETURN 1000;
}ELSEIF ($num >= "2.53" && $num <= "3.13"){
RETURN 900;
}ELSEIF ($num >= "3.14" && $num <= "3.34"){
RETURN 800;
}ELSEIF ($num >= "3.35" && $num <= "3.55"){
RETURN 700;
}ELSEIF ($num >= "3.56" && $num <= "4.26"){
RETURN 600;
}ELSEIF ($num >= "4.27" && $num <= "4.57"){
RETURN 500;
}ELSEIF ($num >= "4.58" && $num <= "5.38"){
RETURN 400;
}ELSEIF ($num >= "5.39" && $num <= "6.29"){
RETURN 300;
}ELSEIF ($num >= "6.30" && $num <= "7.10"){
RETURN 200;
}ELSEIF ($num == "7.11"){
RETURN 100;
}ELSE{
RETURN 0;
}
}
/*
--------------------------------------
Функция комментирования скорости сайта
по баллам
--------------------------------------
*/
FUNCTION SPEED_BALLS_COMMENT($num){
IF ($num >= 2500){
RETURN "<font color='#27CF2E'>".LG('Отлично')."!</font>";
}ELSEIF ($num >= 1500 && $num < 2500){
RETURN "<font color='#27CF2E'>".LG('Хорошо')."!</font>";
}ELSEIF ($num >= 500 && $num < 1500){
RETURN "<font color='orange'>".LG('Слабо')."!</font>";
}ELSE{
RETURN "<font color='red'>".LG('Плохо')."!</font>";
}
}
?>