简体   繁体   English

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

[英]How to prevent slow load time of codeigniter application

I am building an application on codeigniter framework. 我在codeigniter框架上构建应用程序。 I have four types of users 我有四种类型的用户

  • Administrator 管理员
  • Teacher 老师
  • Student 学生
  • Parents 父母

and i have created different controllers and same model file for the users above. 并且我为上述用户创建了不同的控制器和相同的模型文件。 Also each controller file is minimum 150KB and my application being load slower than expected. 另外,每个控制器文件的最小大小为150KB,并且我的应用程序的加载速度比预期的慢。 so if i divide the controller functions in different files and model functions in different then my app will be faster then now?? 所以,如果我将控制器功能划分为不同的文件,并将模型功能划分为不同,那么我的应用程序将比现在更快。

i'm not sure which section costs you time but you mix a lot of actions in this controller function all database actions und readings should be done in a model 我不确定哪个部分会花费您时间,但是您在此控制器功能中混合了很多操作,所有数据库操作和读数应在模型中完成

furthermore if you want to know which things slows down your application, Codeigniter comes with an excellent Benchmarking and Profiling Tool 此外,如果您想知道哪些因素会使您的应用程序变慢,Codeigniter会提供出色的基准测试和性能分析工具

If you want to see a summary you should use the Profiler class - it will display some benchmark results 如果要查看摘要,则应使用Profiler类-它会显示一些基准测试结果

just place this line in your controller 只需将此行放在您的控制器中

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

For further information take a look at the documentation - below are the links 有关更多信息,请查看文档-以下是链接

Codeigniter Profiler Codeigniter探查器

Benchmark Class 基准班

This is the function for book return system 这是退回书系统的功能

 /**********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); } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM