我服务器是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);
}
}
$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);
}
}
如果仅在断电后第一次运行时变慢,那是正常的。因为有很多动态连接库要加载
进一步跟踪的话,我只能想到一点点的echoexit看时间了
如果 $class_name = 'abc';$main = new abc();
//看看是不是实例化abc需要很多时间
比此法好多了。