这个脚本太慢了,有什么办法可以提高它的性能吗?

This script is too slow, any way to improve its performance?

这个脚本太慢了,有什么办法可以提高它的性能吗?通过在页面中返回此函数并在数据库中获取 table 来加载单词。

连接是通过 PDO 和 MySQL 数据库

   function fnc_translate($texto) {
    
        include("conn.php");
    
        $lang['pt-br'] = 'PT_BR';
        $lang['en'] = 'EN';
        $lang['es'] = 'ES';    
        $lang['no'] = 'NO';
    
        if(!isset($_GET['lang']) && !isset($_SESSION['lang'])){
    
            $stmt = "SELECT LANG_PT_BR FROM LANG WHERE LANG_PT_BR=:texto";
            $row_name = "LANG_PT_BR";
            $_SESSION['lang'] = 'pt-br';
    
        }elseif(!isset($_GET['lang']) && isset($_SESSION['lang'])){
    
            $stmt = "SELECT LANG_".$lang[$_SESSION['lang']]." FROM LANG WHERE LANG_PT_BR=:texto";
            $row_name = "LANG_".$lang[$_SESSION['lang']];
    
        }elseif(isset($_GET['lang'])){
            
            $stmt = "SELECT LANG_".$lang[$_GET['lang']]." FROM LANG WHERE LANG_PT_BR=:texto";
            $row_name = "LANG_".$lang[$_GET['lang']];
            $_SESSION['lang'] = $_GET['lang'];
    
        }else{
    
            $stmt = "SELECT LANG_PT_BR FROM LANG WHERE LANG_PT_BR=:texto";
            $row_name = "LANG_PT_BR";
            $lang = $_SESSION['lang'] = 'pt-br';
    
        }
    
        try {
            $sql=$conn->prepare($stmt);
            $sql->bindParam(':texto',$texto,PDO::PARAM_STR);
            $sql->execute();
            $row=$sql->fetch();
        } catch (PDOException $e) {
            return $texto = $texto;
        }
    
        if(isset($row[$row_name])){
            return $texto = $row[$row_name];
        }else{
            return $texto = null;
        }
    }

我的问题解决了!正如您已经想象的那样,问题不在上面的代码中,而是在本地服务器的 PHP.INI 中的设置中。我使用了云设置,速度正常化了。