我服务器是centos的,以下的代码之前是好好的,有一天服务器突然断电了,发现PHP的网站很慢。通过打日志,发现以下$main = new $class_name(); 这个语句居然用了10秒钟,何解呢?各位大侠,有什么好建议?if (class_exists($class_name)){
$main = new $class_name();
$function = $_GET['op'].'Op';
if (method_exists($main,$function)){
$main->$function();
}elseif (method_exists($main,'indexOp')){
$main->indexOp();
}else {
$error = "Base Error: function $function not in $class_name!";
throw_exception($error);
}
}

解决方案 »

  1.   

    除了 $function = $_GET['op'].'Op'; 有毛病外,其他都没有问题
    如果仅在断电后第一次运行时变慢,那是正常的。因为有很多动态连接库要加载
      

  2.   

    请教下这个日志是在哪里查看的
    进一步跟踪的话,我只能想到一点点的echoexit看时间了
      

  3.   

    $main = new $class_name();这个根据你最终的 $class_name 的值来查找实例化的那个类,是不是需要很多时间比如:
    如果 $class_name = 'abc';$main = new abc();
    //看看是不是实例化abc需要很多时间
      

  4.   

    會不會__construct 中做了很多操作?
      

  5.   

    用php 中 的__call
    比此法好多了。