简体   繁体   中英

How to prevent slow load time of codeigniter application

I am building an application on codeigniter framework. 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. 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

If you want to see a summary you should use the Profiler class - it will display some benchmark results

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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