Welcome Guest, Not a member yet? Register   Sign In
Fatal error: Allowed memory size of 8388608 bytes exhausted...
#1

[eluser]kyleect[/eluser]
I'm getting this while viewing one of my controllers:

Quote:Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 1400 bytes) in /Users/kyct/htdocs/imdb/system/codeigniter/Common.php on line 251

controller:

Code:
<?php
class Musicians extends Controller {

    function Musicians()
    {
        parent::Controller();
        $this->load->model('musicians');
    }
    
    function index()
    {
        
    }
    
    function register()
    {
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('musician_name', 'Musician\'s Name', 'trim|required|xss_clean');
        
        if ($this->form_validation->run() == FALSE){
            $this->load->view('musicians/register');
        }else{
            $data = array(
                'name' => $_POST['musician_name']
            );
            $this->musician->register($data);
            redirect('musicians/welcome');
        }
    }
    
    function welcome()
    {
        $this->load->view('musicians/welcome');
    }    
    
}
?>

Does anyone know what this means?
#2

[eluser]Santiago Dimattía[/eluser]
Read this post:
http://ellislab.com/forums/viewthread/58542/#288578

Problem:
You script need to use more than 8mb of memory (Current limit in you webserver).

Solution:
If you webserver allow it, add this line to your index.php file:
Code:
ini_set("memory_limit","12M");
#3

[eluser]cdevroe[/eluser]
I tried all of the solutions that I've seen via Google, on this forum, and the thread that Santiago linked to. No dice. Here is my code.

This is in my Items controller:

Code:
function upload_photo() {
            
            $photoconfig['upload_path'] = './uploads/';
            $photoconfig['allowed_types'] = 'gif|jpg';
            $photoconfig['max_size']    = '2048'; // 2Mb
            
            $this->load->library('upload', $photoconfig);
        
            if ( ! $this->upload_photo())
            {
                $error = array('error' => $this->upload->display_errors());
            }    
            else
            {
                $data = array('upload_data' => $this->upload->data());
            }
            
        return $data;
    } // end do_upload()

This is the error that I'm getting.

"Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 32 bytes) in /Users/cdevroe/Sites/os/system/codeigniter/Common.php on line 245"
#4

[eluser]jedd[/eluser]
Hi cdevroe and welcome to the CI forums.

[quote author="cdevroe" date="1249085158"]I tried all of the solutions that I've seen via Google, on this forum, and the thread that Santiago linked to.[/quote]

You should assume that we don't know the details of all the solutions you found via Google, and consequently you might want to briefly describe the different things you've tried so far. You know .. so that it's easier for the people trying to help you.

Also note that this is a PHP problem, not a CI one, which makes identifying your OS and version numbers so much more important.

Judging by the pathname, I'm guessing you're on a OSX box of some sort. In which case .. well, who knows where it is, but try to find the php.ini file. Find the line in it that says 'memory_limit' and change it - it's presumably set to 20M now (which is weird) and bump it up to something bigger. Restart your web server (no idea how you do that on your OS).
#5

[eluser]cdevroe[/eluser]
First of all, thanks for taking a look at the issue. I am always frustrated when I find forum threads that are left unanswered - and so in that vain I am updating this thread to say that I've solved the issue.

Two things led to the solution of this problem.

1. Properly using the uploading library. I read the documentation more carefully and realized that CodeIgniter was, by default, looking for a element named userfile. I had named my element photo. So I had to change the code slightly in my method. Here is the new method with the slight changes commented.

Code:
function upload_photo() {
            
            $photoconfig['upload_path'] = './uploads/';
            $photoconfig['allowed_types'] = 'jpg';
            $photoconfig['max_size']    = '2048'; // 2Mb
            
            $this->load->library('upload', $photoconfig);
            
            if ( ! $this->upload->do_upload('photo')) // By adding 'photo' it tells CodeIgniter to use that form element
            {
        
                $data = array('error' => $this->upload->display_errors());
            
            } else {
                $data = array('upload_data' => $this->upload->data());
            }            
            
        return $data;
    } // end do_upload()

2. Increasing the amount of memory used by PHP on my local machine. What jedd said was true, I am on Mac OS X. I use my Macbook Pro as my local development environment using MAMP.

For better or worse I did this by adding this line to my root index.php file:

Code:
// ADDED
ini_set("memory_limit","128M");

I hope any of this information proves helpful to anyone that comes across this thread in the future.

To jedd: I will try to write better thread posts in the future should I encounter another problem and need assistance. Thanks for kindly reminding me of proper etiquette.




Theme © iAndrew 2016 - Forum software by © MyBB