为每个用户定义唯一的常量是否会导致php中的性能问题


Does defining unique constants for each user cause performance issues in php?

在我的脚本中,我将一些mysql连接数据添加到常量中,以便于使用。为了安全起见,我试图让常量的名称不那么明显,所以每次用户访问页面时,脚本都会为每个常量添加额外的唯一前缀。我的问题是,常量是以每个用户为基础存储的,还是自最后一个用户在服务器上停止使用以来一直保存在内存中?因此,每个用户的这些额外前缀是否会造成性能问题?

这是脚本:

<?php
date_default_timezone_set('UTC');
class misclassified{
    //pseudo function for getting mysql connection data
    private function mysqlData(){
        return array("host"=>"hostname","user"=>"username","base"=>"base");
    }
    public $prefix = "";
    //defines mysql connection constants
    public function mysqlConnConstants(){
        $data = $this->mysqlData();
        $prefix = crypt(date('ymdgis'),"salty pepper always better")."_";
        $prefix = strtoupper($prefix);
        define($prefix."HOST",$data["host"]);
        define($prefix."USER",$data["user"]);
        define($prefix."BASE",$data["base"]);
        $this->prefix = $prefix;
        return true;
    }
}
?>

更新:

它还打算使用带前缀的变量作为项目中使用的每个文件开头的检查。它看起来是这样的:

<?php
//$prefix - set in main php file where the mysqlMainConstants() is first executed
if(!defined($classReference->prefix."HOST") && !defined($classReference->prefix."USER")): die("Please, try the regular way of using our website!"); endif;
?>

这可能是错误的或无用的,这就是我问的原因,因为起初这听起来很好,可以防止用户知道这些常量并恶意将其应用到脚本中。

假设您希望/需要从数据库中检索数据,那么将值存储为常量的成本并不显著。它们将在PHP执行期间存储在内存中,这是一个HTTP请求。

但更重要的问题是:你为什么要这么做?它不增加操作的安全性,只会使编程环境变得更加复杂。