1
我使用以下代码来检查注释中描述的一些情况。 不幸的是,它降低了页面加载速度。 为了改善功能并正确使用它们,您有什么建议,我该怎么做?优化函数,用于加速应用程序
function insert() {
if ($this - > session - > userdata('logged_in')) { //This is for test whether the user is logged in or not?
if ($this - > siran - > access_level_active()) { //This is because the user name manager is active or not?
if ($this - > siran - > access_level('1', '5')) { //This is for whether or not permission to access this page?
if($_POST){
$this - > load - > view('admin/onepage');
}else{
$this->session->set_flashdata('message_p', $this->lang->line('nopost'));
redirect($this->session->userdata('previous_page'));
}
} else {
$this - > session - > set_flashdata('message', $this - > lang - > line('notaccess'));
redirect($this - > session - > userdata('previous_page'));
}
} else {
$this - > session - > set_flashdata('message', $this - > lang - > line('noactive'));
redirect('login', 'refresh');
}
} else {
$this - > session - > set_flashdata('message', $this - > lang - > line('plslogin'));
redirect('login', 'refresh');
}
}
库笨这三个功能:
public function access_level($mp, $access){
//$mp = '1';
$CI = &get_instance();
$result = $CI->db->get_where('access_level', array('mainpage'=>$mp,'id_relation'=>$CI->session->userdata('id_relation')));
$data = array();
$out = array();
foreach($result->result() as $row){
$dv = json_decode($row->subpage);
$flat = array();
foreach ($dv as $item) {
$flat = array_merge($flat, explode(',', $item));
}
$out = array_merge($out, $flat);
}
if(in_array($access, $out) || in_array('110', $out)){
return true;
}else{
return false;
}
}
public function access_level_active(){
//$mp = '1';
$CI = &get_instance();
$result = $CI->db->get_where('users', array('id'=>$CI->session->userdata('id')));
if ($result->num_rows() > 0){
$row = $result->row();
return ($row->active == 1 ? true : false);
}else{
return false;
}
}
function previous_page(){
$CI = &get_instance();
if ($CI->session->userdata('logged_in')) {
if (isset($_SERVER['HTTP_REFERER']))
{
$CI->session->set_userdata('previous_page', $_SERVER['HTTP_REFERER']);
}else
{
$CI->session->set_userdata('previous_page', base_url());
}
}
}
我的直觉就是你从查询中跑到速度点。你可以记录所有查询并发布一些供我们查看吗?代码本身看起来不是特别密集。有多少用户同时点击导致速度问题? – mkaatman 2013-02-18 22:12:21
http://ellislab.com/codeigniter/user-guide/general/profiling.html,你有没有尝试过使用内置的基准和分析器? – tomexsans 2013-02-18 23:13:12
'$ foo - > bar'不是表示它的传统方式。事实上,它看起来像两个独立的运营商,事实并非如此。您应该使用'$ foo-> bar'代替。 – 2013-02-19 03:07:02