duanchi4184 2014-10-06 18:44
浏览 55
已采纳

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

In my script, I am adding some mysql connection data to constants for easier usage. For safety I am trying to make my constant's names less obvious, so the script adds additional unique prefix to each constant every time an user visits the page. My question is - are the constants stored on per-user basis or are they kept in the memory since the last user stops using it on the server and thus, may those additional prefixes for each user make any performance problem or not?

This is the script:

<?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;

    }

}

?>

UPDATE:

It is also intended to use the prefixed variables as check on the beginning on each file used in the project. It would look like this:

<?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;
?>

It might be wrong or useless and that's why I ask, because at first it sounded me well as an idea to prevent users from knowing those constants and applying them to the script maliciously.

  • 写回答

1条回答 默认 最新

  • doubu1964 2014-10-06 21:11
    关注

    Assuming you want/need to retrieve the data from a database, then the cost to store the values as constants is not significant. They will be stored in memory for the life of the PHP execution, which is one HTTP request.

    But the more important question is: Why would you do this? It adds no security to the operation and only makes it MUCH more complex environment in which to program.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集