Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter: Allowed memory exhausted

I am working in CodeIgniter. What I am trying to do is reading an Excel file and saving to a database. To read the Excel file, I am using this library. After uploading, while reading the Excel file, I am getting this error:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes) in /home/webscwi1/public_html/projects/OnlineExam/application/libraries/excel_reader.php on line 430

Anyhow, I can change the memory size from 12Mb to 512Mb, I'm still getting the same error. I don't know what is the exact error and I want to know whether this is a server error or a problem in the code.

Additional info: If I upload the file with 15 rows, it's working fine, but if I upload with 90 rows in Excel I am getting this error:

 $this->load->library('excel_reader');
 $this->excel_reader->read('question/'.$filename);
 $worksheet = $this->excel_reader->worksheets[0];

Thanks to all.

like image 232
Soundhar Raj Avatar asked Dec 26 '22 10:12

Soundhar Raj


2 Answers

You should increase your Memory limit:

  • editing your php.ini file

    memory_limit = 512M

OR

  • including this line on the top of your script

    ini_set("memory_limit","512M");

You should also check if this lines are on your .htaccess:

php_value memory_limit <value>
php_value upload_max_filesize <value>

Their values override the php configuration. So they should reflect your needs, or simply be removed.

like image 84
Ricardo Miguel Avatar answered Jan 11 '23 10:01

Ricardo Miguel


You should add attribute php_value on your file NameOfProject/.htaccess

<IfModule mod_rewrite.c> php_value memory_limit 256M </IfModule>

like image 26
Mourad MAMASSI Avatar answered Jan 11 '23 08:01

Mourad MAMASSI