如何防止codeigniter应用程序的缓慢加载时间

时间:2016-01-28 07:41:41

标签: php codeigniter

我正在使用codeigniter框架构建一个应用程序。我有四种类型的用户

  • 管理员
  • 教师
  • 学生
  • 家长

我为上面的用户创建了不同的控制器和相同的模型文件。此外,每个控制器文件至少150KB,我的应用程序加载速度低于预期。所以,如果我把控制器功能分成不同的文件和模型功能不同,那么我的应用程序将更快,现在?

2 个答案:

答案 0 :(得分:1)

我不确定哪个部分花费你的时间,但你在这个控制器功能中混合了很多动作 所有数据库操作和读数都应该在模型中完成

此外,如果您想知道哪些事情会降低您的应用程序速度,Codeigniter会提供一个出色的基准测试和分析工具

如果您想查看摘要,您应该使用Profiler类 - 它将显示一些基准测试结果

将此行放在您的控制器中

$this->output->enable_profiler(TRUE);

有关详细信息,请查看文档 - 以下是链接

Codeigniter Profiler

Benchmark Class

答案 1 :(得分:0)

这是图书归还系统的功能

/**********MANAGE LIBRARY/ BOOK RETURN********************/
function book_return($param1 = '', $param2 = '', $param3 = '')
{
if ($this->session->userdata('admin_login') != 1)
redirect('login', 'refresh');
if($param1 == 'create'){
$issue_id = $param2;
$issued_info = $this->crud_model->get_issued_info_for_return($issue_id);

foreach($issued_info as $row) 
{
$data['book_id'] = $row['book_id'];
$data['member_type'] = $row['member_type'];
$data['member_id'] = $row['member_id'];
$data['issue_date'] = $row['issue_date'];
$issue_id = $row['issue_id'];
}
$data['returned_date'] = date("Y/m/d");
$data['status'] = 1;
$this->db->insert('book_return', $data);//can return as default
$stock = $this->crud_model->check_max_available_book_no($data['book_id']);
$dataUpdate['copy_no'] = $stock+1; // as returned +1 the copy no of to the book store
$this->db->where('book_id', $row['book_id']);
$this->db->update('book', $dataUpdate);

// as returned, delete the issue list to the related issue id
$this->db->where('issue_id', $param2);
$this->db->delete('book_issue');

$this->session->set_flashdata('flash_message' , get_phrase('book_returned_successfully'));
redirect(base_url() . 'index.php?admin/book_return', 'refresh');    
}

if ($param1 == 'do_update') {
$data['issue_date'] = $this->input->post('issue_date');
$data['book_id'] = $this->input->post('book_id');
$data['member_type'] = $this->input->post('user_type');
$data['member_id'] = $this->input->post('member_id');
//$data['return_date'] = date('Y/m/d', strtotime($data['issue_date']. ' + '.$this->curd_model->get_max_borrow_days($set_id, $mem_type).' days'));
$data['lib_setting_id'] = $this->input->post('lib_setting_id');
$data['status'] = 1;
$this->db->where('set_id', $param2);
$this->db->update('library_setting', $data);
$this->session->set_flashdata('flash_message' , get_phrase('data_updated'));
redirect(base_url() . 'index.php?admin/library_setting', 'refresh');
} else if ($param1 == 'edit') {
$page_data['edit_data'] = $this->db->get_where('library_setting', array(
'set_id' => $param2
))->result_array();
}
if ($param1 == 'delete') {
$this->db->where('return_id', $param2);
$this->db->delete('book_return');
$this->session->set_flashdata('flash_message' , get_phrase('return_deleted'));
redirect(base_url() . 'index.php?admin/book_return', 'refresh');
}
$page_data['serialNo'] = 1;
$page_data['serialNum'] = 1;
$page_data['book_return_by_staff'] = $this->crud_model->get_book_return_list(2); 
$page_data['book_return_by_student']  = $this->crud_model->get_book_return_list(1);
$page_data['page_name']  = 'book_return';
$page_data['page_title'] = get_phrase('book_return');
$this->load->view('backend/index', $page_data);

}